LearnDash Course Archive SEO

#648786
  • Resolved Dazza
    Rank Math free

    Is it possible to set SEO information for the LearnDash Course Archive? This page is set on the Permalinks section of the WordPress Admin, but there is no actual “Page” for the Courses Archive?

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

    Thank you for contacting Rank Math support and we apologize for the inconvenience.

    Since there is no actual page for the course archive, you would have to use our filter to set the SEO details for this URL programmatically.

    For example, if you want to set the course archive URL to index or noindex, you can use the rank_math/frontend/robots filter, here’s an example of how that would look like code:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
        // Get the current page URL
        $current_url = home_url( $_SERVER['REQUEST_URI'] );
        
        // Define the Course Archive URL
        $course_archive_url = 'https://example.com/course-archive-url'; // Paste your Course Archive URL here
        
        // Check if the current URL is the Course Archive URL
        if ( $current_url == $$course_archive_url ) {
            // Change the robots tag to noindex
            $robots['index'] = 'noindex'; // You can change this to index if you want to set it to index
        }
        
        // Return the modified robots array
        return $robots;
    });

    You can see our complete filter list here: https://rankmath.com/kb/filters-hooks-api-developer/

    We hope this helps you resolve the issue. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.

    Thank you for choosing Rank Math!

    Dazza
    Rank Math free

    Thanks! Can you please confirm if what I’ve done here is correct?

    https://pastebin.com/mqnXViNu

    Hello,

    Thank you for sharing your code with us.

    Your code looks correct to us, except for one minor typo. On line 10 of the pastebin, you have written $$course_archive_url instead of $course_archive_url. This might cause an error or prevent the filter from working properly. Please remove the extra $ sign and try again.

    We hope this helps you resolve the issue. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.

    Thank you for choosing Rank Math!

    Hello again,

    Following up to share more information on this.

    Since you’re adding multiple filters at the same time, a better way to approach this would be to store all the filters you want to use in an array and then loop through each. Something like this:

    <?php
    // Get the current page URL
    $current_url = home_url( $_SERVER['REQUEST_URI'] );
    // Define the Course archive URL
    $course_archive_url = 'https://example.com/courses';
    // Check if the current page is the Courses page
    if ( $current_url == $course_archive_url ) {
        // Use an array to store the filters and values
        $filters = array(
            'rank_math/frontend/robots' => function( $robots ) {
                // Change the robots tag to index
                $robots['index'] = 'index';
                // Return the modified robots array
                return $robots;
            },
            'rank_math/frontend/title' => function( $title ) {
                // Change the page title
                return "Courses Archive – Example";
            },
            'rank_math/frontend/description' => function( $description ) {
                // Change the meta description
                return "Description here yo!";
            },
            'rank_math/frontend/show_keywords' => '__return_true', // Add meta keywords tag
            'rank_math/frontend/keywords' => function( $keywords ) {
                // Change the meta keywords
                return "Courses, Masterclasses, Guitar";
            },
            'rank_math/opengraph/facebook/image' => function( $attachment_url ) {
                // Change the OpenGraph image for Facebook
                return "https://example.com/media/general/branding/courses-banner.jpg";
            },
            'rank_math/opengraph/twitter/image' => function( $attachment_url ) {
                // Change the OpenGraph image for Twitter
                return "https://example.com/media/general/branding/courses-banner.jpg";
            }
        );
        // Loop through the filters and add them
        foreach ( $filters as $filter => $value ) {
            add_filter( $filter, $value );
        }
    }

    Please try this and let us know if it resolves the issue.

    Thank you for choosing Rank Math

    Dazza
    Rank Math free

    Excellent! Thank you so much! So to confirm, this code will overwrite any existing data that’s automatically added to the LearnDash Courses Archive, and no further action is needed?

    Dazza
    Rank Math free

    Also how can I test if these changes are live and working?

    Hello,

    Yes, that filter code will override the old metadata of your archive page.

    You can access the archive’s page source and see if the code is working. Here’s a guide for it: https://www.computerhope.com/issues/ch000746.htm

    You may also use our meta tag analyzer which is much simpler: https://rankmath.com/tools/meta-tag-analyzer/

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

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

You must be logged in to reply to this ticket.