WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Remove current post title from breadcrumbs (19 posts)

  1. Dutchintouch
    Member
    Posted 1 year ago #

    I have seen this question asked regarding Yoast's old Breadcrumbs plugin, but not the breadcrumbs feature in WordPress SEO by Yoast:

    Is there a way to remove the title of the current post (or page) from the breadcrumbs?

    The reason for this question is that I wonder whether repeating the title twice on the post has a detrimental effect.

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. LSB Web Design
    Member
    Posted 1 year ago #

    I would also like to know how to do this. I just want to remove the current post/page from the breadcrumbs.

    Has anyone found a way of doing this?

  3. lcf
    Member
    Posted 1 year ago #

    +1

  4. ViPeRx007
    Member
    Posted 1 year ago #

    I'm trying to figure out how to do this as well...

  5. ViPeRx007
    Member
    Posted 1 year ago #

    I did some digging around and sort of got this working. Or at least it's closer anyway.

    Edit this file:
    /plugins/wordpress-seo/frontend/class-breadcrumbs.php

    Line 267, deleted this:

    if ( isset( $opt['breadcrumbs-boldlast'] ) && $opt['breadcrumbs-boldlast'] ) {
                        $link_output .= '<strong property="v:title">' . esc_html( $link['text'] ) . '</strong>';
                    } else {
                        $link_output .= '<span property="v:title">' . esc_html( $link['text'] ) . '</span>';
                    }

    This removes the current page but I'm not sure exactly how to take off the trailing separator. I'm not sure if this is the best way to accomplish this task considering it'll probably be overwritten with any plugin update, but it's a start.

  6. nathan_dawson
    Member
    Posted 1 year ago #

    This may be a bit late but I removed the title from posts with the following modifications. It doesn't apply to pages but that can be achieved with some tweaks. Also further editing is necessary if you apply styling to the last breadcrumb such as making it bold.

    Edit this file:
    /plugins/wordpress-seo/frontend/class-breadcrumbs.php

    Change line 275:
    $output .= apply_filters( 'wpseo_breadcrumb_single_link', $link_output, $link );

    To:

    if ( $i < ( count( $links ) - 1 ) || ! is_single() )
    				$output .= apply_filters( 'wpseo_breadcrumb_single_link', $link_output, $link );
  7. skmarc
    Member
    Posted 1 year ago #

    First Why did they have such a dumb setting? Repeating of the Title will not be good IMO

    Next thanks a lot to nathan_dawson . It actually works. May be the next update of yoast will take care of this

  8. jrf
    Member
    Posted 1 year ago #

    All,

    There is filter available for this. The breadcrumbs are first put into an array and then send to a method to create the output string. The filter is run just before the links are being send to the output generating method, so you can remove the last item of the array and it should all work ;-)

    Add something along the lines of the following to your (child-)theme's functions.php file:

    function adjust_my_breadcrumbs( $linksarray ) {
    	if( is_array( $linksarray ) && count( $linksarray ) > 0 ) {
    		array_pop( $linksarray );
    	}
    	return $linksarray;
    }
    add_filter( 'wpseo_breadcrumb_links', 'adjust_my_breadcrumbs' );

    This will also upgrade-proof the adjustment.

    Hope this helps!

    Smile,
    Juliette

  9. jrf
    Member
    Posted 1 year ago #

    Actually, you may want to change that code snippet to the below to avoid accidentally removing the category on category pages etc:

    function adjust_my_breadcrumbs( $linksarray ) {
    	$last = count( $linksarray );
    	if( ( is_array( $linksarray ) && $last > 0 ) && isset( $linksarray[$last]['id'] ) ) {
    		array_pop( $linksarray );
    	}
    	return $linksarray;
    }
    add_filter( 'wpseo_breadcrumb_links', 'adjust_my_breadcrumbs' );
  10. lcf
    Member
    Posted 1 year ago #

    @jrf Thanks for the code snippet. I applied on my child theme functions.php but it makes no different.

    theme: canvas
    url: http://www.liewcf.com/maxis-unlimited-data-plan-opera-mini-15297/

  11. Joost de Valk
    Member
    Plugin Author

    Posted 1 year ago #

    They're not from my SEO plugin but from Woo's breadcrumbs function it seems, which uses an old copy of my plugins code. So you'll have to disable it there and then enable the breadcrumbs in WordPress SEO...

  12. lcf
    Member
    Posted 1 year ago #

    @Joost thanks for reply. It is from WordPress SEO. Tested by switching "Breadcrumbs Settings" in WordPress SEO plugin, after I did (again) WooThemes SEO framework import & delete as instructed in http://yoast.com/welcome-woothemes-users/

    Do you have any suggestions? Thank you.

  13. jrf
    Member
    Posted 1 year ago #

    Sorry, small code fix - this should work:

    function adjust_my_breadcrumbs( $linksarray ) {
    	$last = count( $linksarray );
    	if( ( is_array( $linksarray ) && $last > 0 ) && isset( $linksarray[$last-1]['id'] ) ) {
    		array_pop( $linksarray );
    	}
    	return $linksarray;
    }
    add_filter( 'wpseo_breadcrumb_links', 'adjust_my_breadcrumbs' );
  14. lcf
    Member
    Posted 1 year ago #

    @jrf Thanks for the updated code. It works to remove post title, but the category's link is removed as well.

  15. jrf
    Member
    Posted 1 year ago #

    @lcf I see what you mean....

    Well, it's either that or being left with a separator at the end of your breadcrumb...

    If you'd rather have the latter, you can use this in your functions.php file:

    function adjust_single_breadcrumb( $link_output, $link ) {
    	if( isset( $link['id'] ) && strpos( $link_output, 'breadcrumb_last' ) !== false ) {
    		$link_output = '';
    	}
    	return $link_output;
    }
    add_filter('wpseo_breadcrumb_single_link', 'adjust_single_breadcrumb', 10, 2 );

    I'll be sending a pull request to @Yoast to sort this out once and for all in a future version.

    Once that's been accepted & released, you'll be able to use this snippet:

    function adjust_single_breadcrumb( $link_output, $link ) {
    	if( isset( $link['id'] ) && strpos( $link_output, 'breadcrumb_last' ) !== false ) {
    		$link_output = '';
    	}
    	return $link_output;
    }
    add_filter('wpseo_breadcrumb_single_link_with_sep', 'adjust_single_breadcrumb', 10, 2 );

    If you like, you can just add this last snippet to your functions.php file and once my change has been included in the plugin and you've upgraded, it will automatically work for you.

    Hope this helps.

    Smile,
    Juliette

  16. lcf
    Member
    Posted 1 year ago #

    Juliette, thank you!

  17. skmarc
    Member
    Posted 1 year ago #

    @jrf Thanks for the efforts. :)

    We are eagerly awaiting the permanent fix. As of now it looks very ugly and occupies much of the space. Please help the community.

  18. jrf
    Member
    Posted 1 year ago #

    We are eagerly awaiting the permanent fix. As of now it looks very ugly and occupies much of the space. Please help the community.

    I did (help the community)....

    And I have no influence over when the next version will be released.

    P.S.: you can find the pull request here.

  19. Jenni B
    Member
    Posted 7 months ago #

    @jrf Thank you so much! I just stumbled upon this thread, and your last snippet hooking into wpseo_breadcrumb_single_link_with_sep works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic