• Resolved sweettea2

    (@sweettea2)


    Hello!

    I’m trying to create a custom breadcrumb trail to add to the Yoast SEO title and meta description of my WooCommerce product categories. I’ve customized the /woocommerce/templates/global/breadcrumb.php file in my theme folder and have the following in my functions.php file. However, the code prints the breadcrumb list several times and outside the <title></title> tags.

    Please advise as to the best way to fix this, thanks!!

    add_filter( 'woocommerce_breadcrumb_defaults', 'diy_woocommerce_breadcrumbs' );
    function diy_woocommerce_breadcrumbs() {
        return array(
                'delimiter'   => ' ',
                'wrap_before' => '',
                'wrap_after'  => '',
                'before'      => '',
                'after'       => '',
            );
    }
    
    add_filter( 'woocommerce_breadcrumb_defaults',function( $defaults ) {
        unset($defaults['home']);//removes home link.
        return $defaults;//returns rest of links
    });
    
    function get_diy_catlist() {
        return woocommerce_breadcrumb();
    }
    
    // define the action for register yoast_variable replacments
    function register_custom_diyyoast_variables() {
        wpseo_register_var_replacement( '%%diycatlist%%', 'get_diy_catlist', 'advanced', 'some help text' );
    }
    
    // Add action
    add_action('wpseo_register_extra_replacements', 'register_custom_diyyoast_variables');
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    Please use this block code to display the breadcrumb once:

    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb' );

    And for the changes needed by the Yoast plugin, send a ticket to the Yoast developer.

    Good luck

    Thread Starter sweettea2

    (@sweettea2)

    Thanks for your help. This hasn’t fixed the issue with the breadcrumbs displaying more than once, but it may be something with Yoast that’s causing the problem. Will ask them.

    Sorry, please try this one:

    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );

    Thread Starter sweettea2

    (@sweettea2)

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Breadcrumbs in SEO Title’ is closed to new replies.