Dynamic template

#1005279
  • Resolved Paul Cruwys
    Rank Math free

    Hi support,

    We want to purchase the pro version but the backend rank math formula keeps saying everything is poor.
    Our pages are dynamically generated using a template which holds the PHP logic. We have tried to add some code below to get RankMath to see it properly but its not working. Please advise.

    Cheers
    Paul

    add_filter( ‘rank_math/frontend/content’, function( $content ) {
    if ( is_page() ) {
    // Check if current page is using the Z Full Width template
    $template = get_page_template_slug();
    if ( strpos( $template, ‘z_full_width.php’ ) !== false ) {
    // Capture the output from the template file
    ob_start();
    include get_theme_file_path( ‘themes/z_full_width.php’ );
    $rendered = ob_get_clean();
    return $rendered;
    }
    }

    return $content;
    });

Viewing 1 replies (of 1 total)
  • Hello,

    We apologize for the issue you are facing with Rank Math not recognizing your dynamically generated pages properly. Thank you for providing the code snippet you are using.

    It seems like you are trying to capture the output of a specific template and return it for Rank Math to analyze. However, there might be a few things to check:

    1. Template Path: Ensure that the path you are using in get_theme_file_path( 'themes/z_full_width.php' ) is correct. It should point to the actual location of your template file. You might want to use get_template_directory() or get_stylesheet_directory() depending on whether you are using a parent or child theme.

    2. Hook Priority: The filter you are using (rank_math/frontend/content) might need to be adjusted in terms of priority. You can try changing the priority of your filter to ensure it runs at the right time:

      add_filter( 'rank_math/frontend/content', function( $content ) {
         // Your existing code
      }, 10 ); // Adjust priority if needed
    3. Debugging: You can add some debugging statements within your function to see if it is being executed as expected. For example, log the $template variable to ensure it is capturing the correct template slug.

    If these suggestions do not resolve the issue, please reply to this ticket with your site URL so we can further investigate the problem. A human agent from our support team will take over and assist you more effectively.

    Cheers!

    This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.

    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 ‘Dynamic template’ is closed to new replies.