Remove Organization Schema

#773201
  • Resolved Jesus
    Rank Math free

    Hi,

    I would like to be able to remove the organization schema, but only in posts from certain categories. Is this possible?
    I have seen how to remove it from the entire website except for the homepage, but I would need to be able to do it only in the posts of certain categories.
    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Yes, it is possible to remove the Organization Schema from posts in specific categories. You can achieve this by using a code snippet. Here is the code snippet you can use:

    add_filter('rank_math/json_ld', function ($data, $jsonld) {
        if (is_product_category('category-slug')) {
            return [];
        }
        return $data;
    }, 99, 2);

    Replace ‘category-slug’ with the slug of the product category from which you want to remove the Schema. You can also add multiple slugs if you want to remove Schema from multiple categories by extending this code.

    If you have any further questions or need assistance, feel free to reach out to our support team here. We are always here to help.

    Sources:
    Remove Organization Schema from Your Website » Rank Math
    Removing Schema From Your Posts & Pages » Rank Math
    Remove All Schema from Product Category Pages » Rank Math

    Jesus
    Rank Math free

    And if I want remove category or for example some categorys?

    Thanks.

    Hello,

    Thank you for contacting us and bringing your concern to our attention.

    You can use the following filter on your website and see if that works for you:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	global $post;
    	$categories = get_the_terms( $post->ID, 'category' );
    
            // Replace 'category-slug-1', 'category-slug-2' with your actual category slugs
            $exclude_categories = array( 'category-slug-1', 'category-slug-2');
    
            if ( is_array( $categories ) && array_intersect( $exclude_categories, wp_list_pluck( $categories, 'slug' ) ) && isset( $data['publisher'] ) ) {
                unset( $data['publisher'] );
            }
        return $data;	
    }, 99, 2);
    

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

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

    Thank you.

    Jesus
    Rank Math free

    Hi,

    Thanks, But I am also referring to the posts included in that category.

    Hello,

    Thank you for your patience.

    Please update the filter to this one and check again the posts under the category you have defined:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	global $post;
    	$categories = get_the_terms( $post->ID, 'category' );
    
            // Replace 'category-slug-1', 'category-slug-2' with your actual category slugs
            $exclude_categories = array( 'category-slug-1', 'category-slug-2');
    
            if ( is_array( $categories ) && array_intersect( $exclude_categories, wp_list_pluck( $categories, 'slug' ) ) && isset( $data['publisher'] ) ) {
    			$catPost = get_posts(array($exclude_categories)); 
                foreach ($catPost as $post) {
    				unset( $data['publisher'] );
    			}
                unset( $data['publisher'] );
            }
        return $data;	
    }, 99, 2);

    If it’s still not working, please share the actual code you’re using and the sample post where we can check the schema.

    Looking forward to helping 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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Remove Organization Schema’ is closed to new replies.