• Resolved gorfeas

    (@gorfeas)


    WordPress
    Rankmath
    Woocommerce
    WPML
    ACF
    all updated to the latest version.

    I have created a CPT “Traditions” and a custom taxonomy “Seasons” using ACF. I have set the following regarding the URLs

    ACF->Post Types->Traditions->Advanced settings->URLs->Permalink Rewrite=Custom Permalink + URL slug=thrace/traditions/%season%

    ACF->Taxonomies->Seasons->Advanced settings->URLs->Permalink Rewrite=Custom Permalink + URL slug=thrace/traditions/

    The permalinks function as expected and I get for example:
    https://wp.emthrace.org/thrace/traditions/autumn/lorem-ipsum/
    for a single CPT Tradition or
    https://wp.emthrace.org/thrace/traditions/autumn/
    for a custom taxonomy “Seasons” archive page

    https://wp.emthrace.org/thrace/traditions/
    points to a page and not a CPT archive.

    My problem is that the urls and permalinks work just as intended, but I cannot get the breadcrumbs to display in the exact same manner i.e.
    Home / Thrace / Traditions – for the page
    Home / Thrace / Traditions / Autumn / – for the “Seasons” custom taxonomy archive page
    Home / Thrace / Traditions / Autumn / lorem ipsum / for a single “Traditions” custom post type.

    In other words I would like to present breadcrumbs that are identical to the URLs

    In order to achieve that I would have to add “/ Thrace / Traditions /” to the breadcrumb trail of custom taxonomies (Seasons) and custom post types (Traditions). I have played around with filters but I couldn’t get it to work for adding 2 levels of parents.

    Please help

    • This topic was modified 1 year ago by gorfeas.
    • This topic was modified 1 year ago by gorfeas.

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    Thank you for contacting Rank Math support.

    Please use the following filter to modify the breadcrumbs for your CPT posts and taxonomies:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    $thrace = ['Thrace',
    'https://wp.emthrace.org/thrace/'
    ];
    $traditions = ['Traditions',
    'https://wp.emthrace.org/thrace/traditions/'];
    if(get_post_type() == 'tradition') {
    array_splice( $crumbs, 1, 0, array($thrace) );
    array_splice( $crumbs, 2, 0, array($traditions) );
    }
    return $crumbs;
    }, 10, 2);


    Here is how to add a filter to your site:?https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter gorfeas

    (@gorfeas)

    I have tried the above but it doesn’t work

    https://prnt.sc/WMrt9aLL38-B

    https://prnt.sc/QoylJR71f64M

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    Please make sure that the post type’s name is correct in the filter. If the name of your post type is Traditions, you can use the following filter:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    $thrace = ['Thrace',
    'https://wp.emthrace.org/thrace/'
    ];
    $traditions = ['Traditions',
    'https://wp.emthrace.org/thrace/traditions/'];
    if(get_post_type() == 'traditions') { //replace with the name of the CPT
    array_splice( $crumbs, 1, 0, array($thrace) );
    array_splice( $crumbs, 2, 0, array($traditions) );
    }
    return $crumbs;
    }, 10, 2);

    Let us know how that goes. Looking forward to helping you.

    Thread Starter gorfeas

    (@gorfeas)

    That did it! it was that “s” missing. Thank you so much!

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    We are super happy that this resolved your issue.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Thread Starter gorfeas

    (@gorfeas)

    Hi again,

    is there any way I could make this work with my second language?
    https://wp.emthrace.org/thrace/traditions/autumn/
    breadcrumbs display correctly “Home / Thrace / Traditions / Autumn”

    however when switching to greek
    https://wp.emthrace.org/el/thraki/dromena/fthinoporo/
    breadcrumbs display “Αρχικ? / Thrace / Traditions / Φθιν?πωρο”
    Is there a way to display the respective WPML translations? Or just add the translation via some kind of condition within the filter itself in order to display this instead? “Αρχικ? / Θρ?κη / Δρ?μενα / Φθιν?πωρο”

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    One possibility would be to wrap the hard-coded entries for “Thrace” and “Traditions” in the WordPress translation function: https://developer.www.ads-software.com/reference/functions/__/

    After that, it would be possible to include translations for those following the steps here: https://wpml.org/forums/topic/i-want-to-translate-something-through-code/

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    Thread Starter gorfeas

    (@gorfeas)

    I have managed to translate the strings after adding the following lines to the functions.php of my child theme, however breadcrumbs remain unchanged

    $translated = __( 'Thrace', 'rnkmbrdc_thrace' );
    $translated = __( 'Traditions', 'rnkmbrdc_trad' );
    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    You can use the following filter to set the breadcrumbs based on the current language:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    
    $thrace = ['Thrace',
    
    'https://wp.emthrace.org/thrace/'
    
    ];
    
    $traditions = ['Traditions',
    
    'https://wp.emthrace.org/thrace/traditions/'];
    
    $greek_thrace = ['Θρ?κη',
    
    'https://wp.emthrace.org/el/thraki/'];
    
    $greek_tradition = ['Δρ?μενα',
    
    'https://wp.emthrace.org/el/thraki/dromena/'];
    
    if(get_post_type() == 'tradition') {
    
    $my_current_lang = apply_filters( 'wpml_current_language', NULL );
    
    if($my_current_lang == 'el') {
    
    array_splice( $crumbs, 1, 0, array(($greek_thrace) ));
    
    array_splice( $crumbs, 2, 0, array($greek_tradition) );
    
    } else {
    
    array_splice( $crumbs, 1, 0, array($thrace) );
    
    array_splice( $crumbs, 2, 0, array($traditions) );
    
    }
    
    }
    
    return $crumbs;
    
    }, 10, 2);

    Hope that helps. Please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter gorfeas

    (@gorfeas)

    I understand the conditional logic but unfortunately it doesn’t work

    https://prnt.sc/4lbso19WkHyE (new snippet EGNLISH)

    https://prnt.sc/14O4gsW-stEN (new snippet GREEK)

    https://prnt.sc/oE6cyoIpBc7D (old snippet ENGLISH) works

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @grofeas,

    Sorry, we again made the mistake in post type name in the filter. Please replace the tradition with traditions in the filter, and it should work fine:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { $thrace = ['Thrace', 'https://wp.emthrace.org/thrace/' ]; $traditions = ['Traditions', 'https://wp.emthrace.org/thrace/traditions/']; $greek_thrace = ['Θρ?κη', 'https://wp.emthrace.org/el/thraki/']; $greek_tradition = ['Δρ?μενα', 'https://wp.emthrace.org/el/thraki/dromena/']; if(get_post_type() == 'traditions') { $my_current_lang = apply_filters( 'wpml_current_language', NULL ); if($my_current_lang == 'el') { array_splice( $crumbs, 1, 0, array(($greek_thrace) )); array_splice( $crumbs, 2, 0, array($greek_tradition) ); } else { array_splice( $crumbs, 1, 0, array($thrace) ); array_splice( $crumbs, 2, 0, array($traditions) ); } } return $crumbs; }, 10, 2);

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter gorfeas

    (@gorfeas)

    Ah! ok got it! That is just great! thank so much for your time and effort!

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @gorfeas,

    Glad that helped.

    If it isn’t too much to ask for, would you mind leaving us a review here?
    https://www.ads-software.com/support/plugin/seo-by-rank-math/reviews/#new-post

    It only takes a couple of minutes but helps us tremendously.

    It would mean so much to us and would go a long way.

    Thank you.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Breadcrumbs custom taxonomy ACF’ is closed to new replies.