custom canonical to non editable pages

#88738
  • Resolved Krisztina
    Rank Math free

    Hey,
    I would like to add custom canonical URL to 2 archived (not editable under post or pages in dashboard) pages.
    I know only the slug, but cannot edit the page.
    https://prnt.sc/uqw8nz
    I also want to remove these pages from sitemap, but even if I added the slug, the page still in the sitemap.
    https://prnt.sc/uqw7ze

    Thank for your help in advance.
    Krisztina

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

    Thank you for contacting Rank Math today.

    I added the following code to your theme functions.php to have the canonical for the specified pages set to homepage. You can change it to the URL you intend for your canonical.

    
    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	$url = $_SERVER["REQUEST_URI"];
    	
    	$urlLength = strlen($url);
    
    	$isItService = strpos($url, 'service');
    	$isItProject = strpos($url, 'project');
    	if (($isItService!==false || $isItProject!==false) && $urlLength <=11)
    	{
    		$canonical = "https://www.catseo.co.uk/";
    	}
    	return $canonical;
    });
    

    Changing the canonical should automatically remove a page from the sitemap. Please check your sitemap and let us know.

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

    Thank you very much!
    I appreciate your help.

    Kind regards,
    Krisztina

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    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 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this ticket.