Using custom code (add_filter) throws errors

#302912
  • Resolved Derfeuershop.de
    Rank Math free

    As recommended following code is added, to remove showing datePublished or dateModified in search engine results.

    add_filter( “rank_math/snippet/rich_snippet_{$schema}_entity”, function( $entity ) {
    unset( $entity[‘datePublished’]);
    unset( $entity[‘dateModified’]);
    return $entity;
    });

    However this throws the following error. Could you please let me know how to fix this?

    [27-Nov-2021 12:23:39 UTC] PHP Notice: Undefined variable: schema in /var/www/vhosts/xxx.com/httpdocs/wp-content/themes/theme/functions.php on line 724

Viewing 1 replies (of 1 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math.

    You need to change the $schema entity with the Schema Type in the code.

    Here is the correct code:

    add_filter( 'rank_math/snippet/rich_snippet_article_entity', function($entity) {
    unset( $entity['datePublished']);
    unset( $entity['dateModified']);
    return $entity;
    });

    Here is a guide you can follow to add the code correctly:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    I hope this helps.

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

The ticket ‘Using custom code (add_filter) throws errors’ is closed to new replies.