Preview Post Broke in WordPress?

I’ve had a problem with my blog that has been on the back of my mind for a while now; whenever I click the “Preview” button it simply shows my homepage. No errors…. just my homepage. I had a search about and there were suggestions it may be because of the use of a sub-domain (or lack of in my case). So I tried changing a few settings in the admin panel, but still no luck. I thought it may be a .htaccess issue until I enabled the now famous Kubric theme, also know as ‘default’; and suddenly the preview function worked. So it was an issue with my theme… Oops!

My immediate thought was the ‘functions.php’ file since the ‘single.php’ file was pretty much the same as Kubrics. After a few minutes of head scratching I finally solved the issue, my sidebar was breaking things:

1
2
3
4
5
6
7
8
9
10
//Register Sidebars
$p = array(
    'before_widget'  =>   '<li id="%1$s" class="widget %2$s">',
    'after_widget'   =>   '</li>',
    'before_title'   =>   '<h3 class="widgettitle">',
    'after_title'    =>   '</h3>'
);
if (function_exists('register_sidebars')){
    register_sidebars(2, $p);
}

Note the use of ‘$p’, it must be used internally by WordPress. My functions.php was overwriting this variable and breaking the preview function. Once this is changed to ‘$args’ everything worked perfectly:

1
2
3
4
5
6
$args = array(
    //settings here
    );
if (function_exists('register_sidebars')){
    register_sidebars(2, $args);
}

So there you go kids, don’t use ‘$p’ in your themes / plug-ins, use something a little more descriptive for your variable names.

Loading

Webmentions