Is there a way to insert existing schema template using functions.php?

#637287
  • Resolved Anonymous
    Rank Math free

    Hi,

    I would like to insert a schema template on all subpages under a specific parent page.

    My own idea is that it must be possible to do with a little php.

    So my question is:
    Is there a way to insert existing schema template using functions.php?

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

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

    The Schema Template feature is only available to Rank Math PRO:
    https://rankmath.com/kb/schema-templates/

    However, to insert a custom schema on your site on the free version, you can use and customize our filter here:
    https://rankmath.com/kb/filters-hooks-api-developer/#extend-json-ld-data

    Hope that helps.

    Thank you.

    Anonymous
    Rank Math free

    Hi Reinelle,

    The client that I am working on has Rank Math Pro and they have already set up a Schema Template.

    But how can I insert the template with functions.php?

    function insert_existing_schema_template() {
      if ( is_page() && in_array( 39567, get_post_ancestors( get_the_id() ) ) ) {
        // enqueue stuff
      }
    }
    add_action('wp_head', 'insert_existing_schema_template');

    Hello,

    Unfortunately, we don’t have a filter function to programmatically insert any schema template into a specific set of pages.

    If you are using our filter code to extend the current schema structure of the page, it is then possible to specifically construct a custom schema there but instead of using our UI, you are programmatically adding and modifying the schema properties. Here’s an example:

    add_filter('rank_math/json_ld', function ($entity) {
    	if (is_page() && in_array(39567, get_post_ancestors(get_the_id())) && $entity['publisher']) {
    		$entity['publisher']['@type'] = 'Corporation';
    		$entity['publisher']['@id'] = 'https://somewebsite.com/corpo-stuff/';
    	}
    
    	return $entity;
    });

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    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 ‘Is there a way to insert existing schema template using functions.php?’ is closed to new replies.