WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Yoast Breadcrumbs] Obscure Bug in Post Preview

[Resolved] [Plugin: Yoast Breadcrumbs] Obscure Bug in Post Preview

  • Hi,

    A StudioPress user found a bug in the breadcrumbs.php file that comes with our themes. It’s very obscure.

    When a post is previewed and has no categories selected it will not return a category and get_the_category() will return an empty array instead of an array of objects.

    In your files, yoast-breadcrumbs.php needs to be changed:

    if (is_single() && $opt['singlecatprefix']) {
        $cats = get_the_category();
        $cat = $cats[0];
        if ($cat->parent != 0) {
            $output .= get_category_parents($cat->term_id, true, " ".$opt['sep']." ");
        } else {
            $output .= '<a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a> '.$opt['sep'].' ';
        }
    }

    Can be re-written as:

    if (is_single() && $opt['singlecatprefix']) {
        $cats = get_the_category();
        $cat = $cats[0];
        if ( is_object($cat) ) {
            if ($cat->parent != 0) {
                $output .= get_category_parents($cat->term_id, true, " ".$opt['sep']." ");
            } else {
                $output .= '<a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a> '.$opt['sep'].' ';
            }
        }
    }

    HTH,

    –Charles

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks Charles,

    Updated in the plugin and will update it in the StudioPress themes too!

    Hello, thank you it worked! But it is the home page with the message “Sorry, no posts matched your criteria.” and shows the initial posts on the page how to?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: Yoast Breadcrumbs] Obscure Bug in Post Preview’ is closed to new replies.