最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - Wordpress display breadcrumbs using Yoast plugin

programmeradmin2浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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!

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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!

Share Improve this question asked Apr 10, 2020 at 16:31 sd100sd100 112 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

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/">Home</a> » 
            <span><a href="https://yoast/help/">Help center</a> » 
                <span><a href="https://yoast/help/category/wordpress-plugins/">WordPress plugins</a> » 
                    <span><a href="https://yoast/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.

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' );

发布评论

评论列表(0)

  1. 暂无评论