Issue with Category Shortcode

#8139
  • Resolved CharlieB
    Rank Math free

    Hello Rank Math,

    I am having an issue with the %category% short code when adding it to the Single Title.

    https://www.screencast.com/t/I4Q32LtRH

    must be a bug because it converts it to “tegory%” or “tegories”

    Also it will NOT output the Category name to the description if used there.

    • This topic was modified 4 years, 10 months ago by CharlieB.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    The first problem suggests that there is a conflict with one of your installed plugins. Please help us investigate this by performing the steps described here: https://rankmath.com/kb/check-plugin-conflicts/

    Since your restaurant custom post type is using a custom category, the default %category% replacement variable will not work for this post type and you have to register some custom replacements to get the category. I could not access your theme files but here is a similar topic on how to register the replacements: https://support.rankmath.com/ticket/register-a-custom-template-variable/

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Thanks.. that is disappointing. I have 3 custom directory types in my Theme. Not sure what that means for me. Seems complicated. And why a plugin would conflict with this one shortcode only in this particular location….frustrating. Thanks for your help. Have a good day.

    Hi Charlie,

    Thanks for the follow up.

    We would be happy to help in adding the custom replacement variables to your theme if you can share some temporary FTP access as well on the sensitive data section.

    I am looking forward to your response. Thank you.

    Michael,

    My problem is that with my FTP I have one login and can’t setup temporary logins. I trust you but my concern is the internet… hope you understand. If you can instruct me I can add this to the theme.

    In my case I have 3 Directory Types and they are Listings, Restaurants and Accommodations.

    The other problem I have is the potential plugin conflict that I haven’t figured out yet. Can’t understand this and what could be causing it.

    Thoughts?

    Hi there,

    I completely understand the security limitation.

    Here is a copy of the code that you can use to register some custom replacements for one of the categories “Listing Category”, I have added some comments on the code for the areas that you will need to change when reusing the code for a new category:

    /*
    * Add a new copy of the following for each of your categories 
    * 
    * The code below will register a %listingCat% variable to be used on the Listing Category page
    */
    add_action( 'rank_math/vars/register_extra_replacements', function() {
        //replace 'listingCat' with the name of the variable that you would to create and use for each category
        //replace all occurences of'RMPrimaryCategoryToListingCallback' with a new function name when adding a new replacemnt variable
        //for a new category
       RankMath\Helper::register_var_replacement( 'listingCat',array('RMPrimaryCategoryToListingCallback'),$args = array(
                'name'    => esc_html__( 'Listing Category', 'rank-math' ),
                'desc'    => esc_html__( 'Category of the current listing', 'rank-math' ),
                'example' => esc_html__(RMPrimaryCategoryToListingCallback())));
        
        
    } );
    
    function RMPrimaryCategoryToListingCallback(){
        global $post;
        $post_id = $_GET['post'] ?: $post->ID;
        //replace 'listing_cat' with the new variale slug of the category that you are registering new replacements for
        $termID = \WilokeListingTools\Framework\Helpers\GetSettings::getPrimaryTermIDOfPost($post_id, 'listing_cat');
        if ( !empty($termID) ){
            //replace 'listing_cat' with the new variale slug of the category that you are registering new replacements for
          $oTerm = get_term($termID, 'listing_cat'); 
          if ( !empty($oTerm) && !is_wp_error($oTerm) ){
             return $oTerm->name;
          }
       }
    
    }

    The conflict is a bit odd but I cannot reproduce this on my end which suggests that there is a plugin or theme code causing this on your end. To be able to get to the bottom of the conflict, I would suggest that you perform the steps I recommended earlier.

    I hope this info helps. Thank you.

    Michael,

    Where does this code go?

    Hi there,

    Thanks for the question.

    This will go in your functions.php file.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Issue with Category Shortcode’ is closed to new replies.