Default Canonical For Custom Post Type

#37124
  • Resolved Lloyd Silver
    Rank Math pro

    Is there any way we can set the default canonical link for a custom post type so that all of the posts within that CPT are pointing to a specific URL as the canonical?

    My use case is we’re developing partner pages that are using a version of the home page and want a canonical on all of those pages to be the home page of the site.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    You can set the canonical URL manually in the Advanced SEO meta box while creating the pages.

    Hope this helps. Thank you.

    ​​​​​​

    Lloyd Silver
    Rank Math pro

    Right, I was hoping there was a way of changing the default canonical for all of the posts within the CPT.

    Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    You can modify the canonical value for the custom post type by creating some custom PHP logic within the following filter:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	return $canonical;
    });

    Looking forward to helping you. Thank 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Default Canonical For Custom Post Type’ is closed to new replies.