Duplicate Meta description in custom post type – Recipes

#601716
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thanks for contacting us and sorry for the inconvenience caused.

    You should check the settings of your theme and if there is no option to disable their description then we can’t help you with removing that as this is something that can be managed by their developers.

    If you want to remove the description of our plugin, please use the following filter:

    add_filter( 'rank_math/frontend/description', function( $description ) {
    	if (get_post_type() == 'recipe') { //replace recipe with the correct name of the post type
    		return false;
    	}
    	return $description;
    });;

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

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

    Anonymous
    Rank Math free

    Hi Jaideep,
    there is no option in theme and their developer tried but I guess they do not want to remove that and said, they do not cover this in support. they also tried removing rank match description but it gets removed from everywhere as well,
    So, I tried your fix It works BUT it removed description from recipe categories as well like: cuisine, cooking method, course
    Is there any way to remove just from single recipe listings?

    Thanks
    Vinod

    Hi there,

    Thank you for getting back to us.

    You should be able to modify this filter to work for only specified post IDs. You can do that by using the get_the_ID() function, which returns the ID of the current item in the WordPress loop. You can find more information about this function here: https://developer.wordpress.org/reference/functions/get_the_id/

    To use this function, you need to find the post IDs of the posts you want to exclude. You can get the ID of your posts by editing the post and looking at the URL for the post id. Like this:

    For example, if you want to remove the description for posts with IDs 123, 456, and 789, you can use this code:

    add_filter( 'rank_math/frontend/description', function( $description ) {
    	$post_id = get_the_ID(); //get the current post ID
    	$target_ids = array(123, 456, 789); //set an array of the target post IDs
    	if (get_post_type() == 'recipe' && in_array($post_id, $target_ids)) { //check if the current post type is recipe and if the current post ID is in the target array
    		return false; //remove the description
    	}
    	return $description; //return the original description
    });

    You can modify this code to suit your needs by changing the post type and the target IDs. Try this code and let us know if it works for you.

    We hope this helps. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again.

    Thank you for choosing Rank Math!

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Duplicate Meta description in custom post type – Recipes’ is closed to new replies.