Hi so for all my Wordpress 5.4 site’s posts (articles), I'm using Yoast SEO plugin for breadcrumbs across my site.

For all my posts (articles) I just want:

Home > CategoryLink > as breadcrumbs, not the topic of the post.

So I’ve tried the following code in my theme's functions.php:

 add_filter( ‘wpseo_breadcrumb_links’, ‘wpseo_breadcrumb_remove_postname’ );

function wpseo_breadcrumb_remove_postname( $links ) {

if( sizeof($links) > 1 ) {

array_pop($links); }

return $links;

}

However, what the hack above does is it also removes the previous link (parent link) and publishes only text instead of a link.

So if I have links as follows:

Home> CategoryUrl > Title of Post

Applying the patch into functions.php results in this:

Home > CategoryText

So the Category name is not a link anymore but a text. So breadcrumbs are useless after this hack.

Is there a correct way of not displaying post title in the breadcrumbs using Yoast? Thanks!

有帮助吗?

解决方案 2

function remove_breadcrumb_title( $link_output) {
if(strpos( $link_output, 'breadcrumb_last' ) !== false ) {
    $link_output = '';
}
return $link_output;

} add_filter('wpseo_breadcrumb_single_link', 'remove_breadcrumb_title' );

其他提示

I went to the Yoast website and just took a look at the breadcrumbs they use:

<nav class="row breadcrumb" aria-label="You are here:">
    <span>
        <span><a href="https://yoast.com/">Home</a> » 
            <span><a href="https://yoast.com/help/">Help center</a> » 
                <span><a href="https://yoast.com/help/category/wordpress-plugins/">WordPress plugins</a> » 
                    <span><a href="https://yoast.com/help/category/yoast-seo-woocommerce/">Yoast SEO: WooCommerce</a> » 
                        <span class="breadcrumb_last" aria-current="page">How to implement Yoast SEO breadcrumbs</span>
                    </span>
                </span>
            </span>
        </span>
    </span>
</nav>

You'll notice that the last nested <span> tag has a class of .breadcrumb_last.

You could add the following to your style.css:

nav.row.breadcrumb .breadcrumb_last{
    display:none;
}

This may actually be advisable because the aria-current is still available for assistive technologies.

I should add that this operates on the assumption that the way your breadcrumbs are being output is the same HTML format, so you'll need to check that first, but if it is, this should address it. You may also need to, and I'm loathe to say this, add an !important to your CSS rule in case Yoast's stylesheet executes after yours. Try without it though and see what happens.

许可以下: CC-BY-SA归因
scroll top