• Resolved Wagner

    (@atendimentoacionista)


    Hello,
    Some partners have asked to change the canonical tag to the source pemalink.
    I tried the code bellow in functions.php but it crashes de site.
    Is there any other way to do it?

    add_action( 'wp_head', 'etruel_add_meta_tag', 0 );
    function etruel_add_meta_tag() {
    	global $post;
    	$post_id = $post->ID;
    	$post_permalink = get_permalink( $post_id, false );
    	
    	$wpe_campaignid = get_post_meta( $post_id, 'wpe_campaignid', true );
    	$wpe_sourcepermalink = get_post_meta( $post_id, 'wpe_sourcepermalink', true );
    
    	if (has_category('category-slug',$post->ID)){
    		remove_action('wp_head', 'rel_canonical');
    		echo '<link rel="canonical" href="'.$wpe_sourcepermalink.'" />';
    	}
    }
  • The topic ‘Caonical tag’ is closed to new replies.