๐ ๏ธ 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
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