Wordpress XML Parsing Error for sitemaps
If a client ends up breaking their sitemap we’d usually have the arduous task of finding somewhere in wordpress the extra one or two white space before and after the php tags <?php
and ?>
If you do not have shell access to your wordpress directory, then I suggest checking your wp-config.php
in the root directory, and remove all excess spaces at the top. And then checking your functions.php
in your theme directory for the extra spaces.
This code will search your theme directory for any files which contain white space at the top or bottom of your files so that at least you don’t have to search through all the files.
#!/bin/bash
url=$1
dir=/var/www/$url/wordpress/wp-content/themes/
if ! [[ -d $dir ]]; then
echo "The url "$url" isnt a valid url"
exit 1
fi
cd $dir
files=( $(find . -iname *.php) );
echo Total Files to Search: ${#files[@]}
echo Searching...
for i in ${files[@]}; do
head=$(head -n1 $dir$i | sed 's/r//')
tails=$(tail -n1 $dir$i | sed 's/r//')
if [[ $head == "" ]]; then
echo $i : Head Matched : $head
fi
if [[ $tails == "" ]]; then
echo $i : Tail Matched : $tails
fi
done
echo Finished Searching