Issue with SEO Score for Pages Using PHP Templates in Gutenberg (Block Theme)

#1049329
  • Resolved Muhammad
    Rank Math pro

    Hey, Rank Math Support Team!

    I’m using a Gutenberg (Block) theme and have created several custom PHP page templates, which are assigned to specific pages. These templates contain rich, static HTML content following proper on-page SEO practices that Rank Math generally recommends.

    However, since the content is not within the default WordPress editor (i.e., post_content), Rank Math doesn’t seem to detect it, resulting in a low SEO score (around 40) for all those pages.

    To address this, I attempted to use the rank_math/frontend/content filter like this:

    // Hook only in admin area (editor or REST API)
    if ( is_admin() || defined( 'REST_REQUEST' ) ) {
    	add_filter( 'rank_math/frontend/content', 'mysite_rankmath_frontend_content' );
    }

    The callback function includes the PHP template, captures its output, and returns the rendered content so Rank Math can analyze it. Unfortunately, this approach doesn’t seem to update the SEO score in the admin/editor area.

    Could you please:

    * Confirm whether I’m using the correct hook and approach?
    * Let me know if there’s an officially supported way to load and verify template-based content in the Rank Math content analyzer, especially for block themes?

    Looking forward to your guidance.

    Thank you.

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

    We apologize for the issue you are facing with the SEO score for your pages using PHP templates in a Gutenberg (Block) theme. Thank you for providing detailed information about your setup and the steps you’ve taken so far.

    To address your concerns:

    1. Correct Hook and Approach: The rank_math/frontend/content filter is indeed a valid approach to modify the content that Rank Math analyzes. However, it seems that your implementation might not be capturing the output correctly or may not be applied in the right context. Ensure that your callback function is properly defined and that it returns the rendered content as expected.

    2. Officially Supported Way: Currently, there isn’t a specific official method documented for loading and verifying template-based content in Rank Math for block themes. However, you can try using the rank_math/frontend/content filter more effectively by ensuring that it captures the output of your PHP templates correctly. You might also want to check if there are any specific conditions or additional filters that need to be applied based on your theme’s structure.

    If you continue to experience issues, we recommend replying to this ticket with your site URL and any additional details about your PHP templates. A human agent from our support team will be able to assist you further and provide more tailored guidance.

    Thank you for raising this concern, and we appreciate your patience as we work to resolve it!

    Sources:
    Enable Rank Math SEO on Elementor Templates » Rank Math

    P.S: I added this code in the child theme functions.php

    I’ve added the page link and dashboard screenshot in the Sensitive Data area. Please lemme know if you need anything else?

    Thank you.

    Hello, Team!

    Is there any update on the ticket?

    Hello, Team!

    I hope you’re doing well. I’m following up on a support ticket I submitted a few days ago. Could you please check the status and let me know if there are any updates?

    Your assistance would be greatly appreciated.

    Hello,

    Thank you for contacting Rank Math support, and sorry for the unexpected delays and any inconvenience that might have been caused due to that.

    The filter code you presented will not work here. The processing of content happens in real-time so this integration may involve client script, not just from the backend.

    To include your custom template content in the SEO analysis, you’ll need to use our Content Analysis API. Specifically, hook into rank_math_content using JavaScript and provide the rendered content from your template. This allows Rank Math to analyze it in the editor and update the SEO score accordingly.

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

    It doesn’t seem to be working. I believe this approach might work with the Gutenberg editor content only, but not when the template content is created through a .php file.

    Hello,

    The Content Analysis API is designed to work within the block editor context and doesn’t analyze content rendered solely via PHP templates outside the editor.

    Unfortunately, since Rank Math analyzes what’s present in the editor, static content output directly via PHP templates won’t be picked up automatically. A possible workaround is to mirror your template content into a hidden custom field and pass that content into Rank Math using the Content Analysis API (rank_math_content filter in JS).

    We understand this isn’t ideal, and we’ve noted this limitation for future improvements.

    Don’t hesitate to get in touch with us if you have any other questions.

    Thanks for adding this limitation to future improvements.

    Hello,

    We are super happy that we were able to address your concerns.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Issue with SEO Score for Pages Using PHP Templates in Gutenberg (Block Theme)’ is closed to new replies.