• Resolved laracroftofficial

    (@laracroftofficial)


    Hi guys!
    Thanks for your plugin!
    I’m using yoast seo – 20.1 and have a question about title for the categories.
    I need to show title for all categories in format
    “Title of current category – Title of parent category”
    Then I insert a variable %%term_hierarchy%% I have almost that I need, but in wrong order:
    “Title of parent category – Title of current category”
    Also I can’t find a way to get title from parent category as separate variable which I could combine with %%term_title%%.
    I have an idea to make my own variable for this, but I hope that existing more simple way to achieve my goal.

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello @laracroftofficial

    Thanks for using the Yoast SEO plugin. To show the hierarchy, you only need to use %%term_hierarchy%%. That gives the parent category separator child category. With that, you wouldn’t need to use the %%term_title%% else the child category will be duplicated.

    However, if you’re referring to having a separate variable for the parent and another for the child category, you may consider creating custom variables to suit your needs.

    Thread Starter laracroftofficial

    (@laracroftofficial)

    Hi @maybellyne
    Yes, you’re right.
    But I need to modify order in %%term_hierarchy%% for this order:

    child category separator parent category.
    Is it possible?

    Plugin Support Maybellyne

    (@maybellyne)

    Hello @laracroftofficial I’m unaware of the possibility of changing the order

    Thread Starter laracroftofficial

    (@laracroftofficial)

    Okay!
    I’ve created my own variable for this:

    // define the custom replacement callback
    function get_myname() {
        $curr_cat = get_queried_object();
        if($curr_cat->parent > 0):
            $parentcats = get_ancestors($curr_cat->term_id, 'product_cat');
            foreach($parentcats as $parent):
                $cat = get_term($parent,'product_cat');
                $cat_name = $cat->name;
            endforeach;
        else:
            $cat_name = $curr_cat->name;
        endif;
        return $cat_name;
    }
    
    // define the action for register yoast_variable replacments
    function register_custom_yoast_variables() {
        wpseo_register_var_replacement( '%%myname%%', 'get_myname', 'advanced', 'text' );
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Title for woocommerce categories’ is closed to new replies.