Wordpress - adding post category requires page refresh to show up Wordpress - adding post category requires page refresh to show up wordpress wordpress

Wordpress - adding post category requires page refresh to show up


Just in case anyone else runs into this problem, one of the main reasons stuff like this could go wrong is because of white space before and after the opening and closing PHP tags, respectively, in your functions.php file of your theme.

More information can be found in the Wordpress FAQ and troubleshooting section.


I experienced this issue today, and white space in PHP files was the problem.

However, I want to share the steps I took to resolve the issue:

  1. I tried opening every PHP file and checking for blank lines at the start and end of the file. I picked up a few problems but the issue persisted.
  2. I was also able to do a regex search in my IDE for problems. I used Textmate/Regex: Strip whitespace from beginning/end of file as a reference point and [without quotation marks] the following regex searches "\?>[\r\n\t ]+" to find space/blank lines at the end of a file, and "[\r\n\t ]+<\?" for the start of a file.
  3. There were still problems so I narrowed down the scope by disabling plug-ins (I also knew it was one of my own plug-ins in the site I'm developing, so that made it easier).
  4. Re-activating a plug-in give a warning "The plugin generated X characters of unexpected output during activation". This helped me in the trial-and-error process of narrowing down the source.
  5. Once I had the plug-in identified, I started commenting out require_once() calls in PHP files until the "The plugin generated X characters of unexpected output" warning disappeared.
  6. Eventually, I realised I'd broken the plug-in during refactoring and was doing a require_once() on a PHP file that was pure HTML (to inject favicon tags into a page header) rather than the appropriate add_action() call on the file as I originally intended.

Hopefully, these debug steps provide some inspiration to other people suffering the same problem. As far as I know, WordPress does not offer any easy way to identify the cause of this problem (i.e. it does not identify which file has bad spaces in it).