ฯŸThex Documentation
Article #4

๐Ÿ› ๏ธ How to Fix a WordPress Theme with PHP Short Tags

If your WordPress theme suddenly stops working after moving to a new server, one common cause is PHP short tags (<?) inside the theme files.

Updated Aug 27, 2026

๐Ÿ› ๏ธ How to Fix a WordPress Theme with PHP Short Tags

If your WordPress theme suddenly stops working after moving to a new server, one common cause is PHP short tags (<?) inside the theme files.

Instead of editing hundreds of files manually, you can fix the theme directly from SSH with a few commands.

๐Ÿ”ง 1. Enter the Themes Directory

cd /var/www/DOMAIN/html/wp-content/themes

๐Ÿ’พ 2. Create a Full Backup First

Replace THEME with your actual theme folder:

cp -a THEME "THEME-backup-$(date +%Y%m%d-%H%M%S)"

This gives you a complete backup before making any changes.

๐Ÿ”„ 3. Convert PHP Short Tags

This converts only:

<?

to:

<?php

without changing normal <?php or <?= tags.

find "/var/www/DOMAIN/html/wp-content/themes/THEME" \
-type f -name "*.php" -print0 |
xargs -0 perl -pi -e 's/<\?(?!php|=)/<?php/g'

๐Ÿ” 4. Check for Remaining Short Tags

grep -RInP --include='*.php' '<\?(?!php|=)' \
"/var/www/DOMAIN/html/wp-content/themes/THEME"

If nothing is returned, there are no remaining PHP short tags in the theme.

โœ… 5. Check Every PHP File for Syntax Errors

Using the active PHP 7.4 LSPHP binary:

find "/var/www/DOMAIN/html/wp-content/themes/THEME" \
-type f -name "*.php" -print0 |
while IFS= read -r -d '' file; do
    if ! /usr/local/lsws/lsphp74/bin/lsphp -l "$file" >/dev/null 2>&1; then
        echo "SYNTAX ERROR: $file"
    fi
done

Any file reported as:

SYNTAX ERROR:

needs to be checked before continuing.

๐Ÿš€ 6. Restart OpenLiteSpeed

/usr/local/lsws/bin/lswsctrl restart

โš ๏ธ Important

on code ALL


cd /var/www/DOMAIN/html/wp-content/themes

cp -a THEME "THEME-backup-$(date +%Y%m%d-%H%M%S)"

find "/var/www/DOMAIN/html/wp-content/themes/THEME" \
-type f -name "*.php" -print0 |
xargs -0 perl -pi -e 's/<\?(?!php|=)/<?php/g'

grep -RInP --include='*.php' '<\?(?!php|=)' \
"/var/www/DOMAIN/html/wp-content/themes/THEME"

find "/var/www/DOMAIN/html/wp-content/themes/THEME" \
-type f -name "*.php" -print0 |
while IFS= read -r -d '' file; do
    if ! /usr/local/lsws/lsphp74/bin/lsphp -l "$file" >/dev/null 2>&1; then
        echo "SYNTAX ERROR: $file"
    fi
done

/usr/local/lsws/bin/lswsctrl restart


Always create the backup before modifying the theme.

Also, this procedure is specifically for environments using the PHP/LSPHP version shown in the command. If your server is running another PHP version, use its corresponding LSPHP binary.

๐Ÿ’ก Save this post โ€” it can save you a lot of time when a WordPress theme breaks after a server migration or PHP configuration change.

#WordPress #WordPressTips #PHP #OpenLiteSpeed #LSPHP #Linux #WebHosting #ServerManagement #THEX