WordPress Developer Debug.

When developing themes and plugins for WordPress I often find myself with the dreaded white page – or just half a page with no useful error information.

You may already know about the WP_DEBUG constant, if you don’t its found in your wp_config.php file and you just change it to…

define('WP_DEBUG', true);

to turn it on debugging.
Chances are that with this turned on your WordPress will start spewing out a load of warnings you never even knew were happening!

This ‘error noise’ is fine for a development site. But what about if your site is live and need to code a new feature?

I came up with this little trick so I can turn on debug mode in the page request.

$debugmodeon = false;
if (isset($_GET['debug'])) {
	if ($_GET['debug'] != "") { 
		$debugmodeon = true;
	}
}
define('WP_DEBUG', $debugmodeon);

Just add ?debug=true and voilà – debugging info only when you need it 😉

Once your done – you’ll want to swap back to define('WP_DEBUG', false); so your ‘debug mode’ can’t be triggered by accident..

WordPress Fixes: Showing content – not excerpt in searches.

Came across this one and it took a little tracking down to fix – so in case someone else has this issue – heres how i fixed it 😉

Came across this one and it took a little tracking down to fix – so in case someone else has this issue – here’s how I fixed it 😉

The Problem…

Search result pages in WordPress are showing a generated snippet from the post content, not the excerpt.   After confirming that the post does indeed have a custom excerpt specified for it, here’s what I did next…

the_excerpt()

First thing to do is the check is that you are using the_excerpt() in your template.  Look in your /wp-content/themes/[yourtheme] folder for search.php or if that’s not there – index.php.

In that file find the wordpress loop – it’ll start like this…
while (have_posts()) : the_post();

Make sure it has the_excerpt(); not the_content();, it could be like this

<?php if (is_archive() || is_search()) { ?>
    <?php the_excerpt(); ?>
<?php } else { ?>
    <?php the_content(); ?>
<?php } ?>

If you can see the_excerpt() – chances are you have the right template.

Plugins…

Once you’ve confirmed the templates is correct and the post has an excerpt, then you need start disabling plugins.
If possible turn them all off – then enable one at a time till you find the offender.
If it still happens with all plugins disabled, then its definitely your theme that’s to blame.

For me..

In my case the problem turned out to be (obviously with hindsight) Relevanssi. Relevanssi has an option to reformat your search result content to show the relevant result. This most likely results in a part of the content being shown – not the excerpt you specified. Its just a tickbox away to fix (Create custom search result snippets) 😉

Hope this helps save someone some time debugging!