ThemeShaper Forums » Thematic

[closed]

How to disable <link rel="canonical"?

(15 posts)
  • Started 4 years ago by mpanda
  • Latest reply from mpanda
  • This topic is resolved
  1. mpanda
    Member

    Hello,

    I'd need to disable meta canonical tag in specific pages.
    I use WP 286 with Thematic 0951.

    Any suggestion is much appreciated.

    Thanks,

    Mario

    Posted 4 years ago #
  2. Hi mpanda,

    This should work for WP 2.8-2.9.2 + Thematic .9.5.1-.9.6.1

    function remove_thm_canonical($thm_canonical_link) {
    	/* add the conditioal tags you want
    		to remove the canonical link */
    	if ( is_page() ) {
    		// remove action for  WP 2.9+ function
    		remove_action( 'wp_head', 'rel_canonical' );
    		// empty Thematic's canonical link
    		$thm_canonical_link = null;
    	}
    	/* check for the WP 2.9 before passing on Thematic's
    		duplicate canonical link for all is_singular()	*/
    	if ( !function_exists ('rel_canonical') ) {
    		return $thm_canonical_link;
    	}
    }
    add_filter('thematic_canonical_url', 'remove_thm_canonical');

    This function is set to remove it from all pages. You'll have to adjust the conditional tag to account for only the pages you want this to work on.

    -Gene

    Posted 4 years ago #
  3. mpanda
    Member

    Hi Gene,

    thanks for your reply.

    Have I to add that code to Thematic's functions.php?

    More, where you say 'to adjust' do you mean I have to specify just page's title or the entire permalink?

    That's very important to me as I need to prevent canonical tag for some paginated contents (eg. italy/hotels/rome/2, /rome/3, rome/4 etc etc)

    Thank you,

    Mario

    Posted 4 years ago #
  4. You should add this to the functions.php of a child theme. There is a sample child theme folder included with Thematic. Move that directory one leve up to the themes folder and activate it in the admin>appearance >themes.

    Then make you edits to that child theme's function.php adding the code above. The only part if that code you to need change is:

    if ( is_page() ) {
    You could use the page id, title, or slug to target specific pages with that if statement. Look here to find out more about conditional tags http://codex.wordpress.org/Conditional_Tags

    What do you mean by "paginated contents" do you mean child/parent page relationships or a single page that uses the <!--nextpage--> tag.

    -Gene

    Posted 4 years ago #
  5. mpanda
    Member

    "You should add this to the functions.php of a child theme..."
    That's a problem as I don't use child theme...I know that many here in forum don't like that...:)....sorry
    Can I do same way by mother theme?

    "or a single page that uses the <!--nextpage--> tag"
    That I mean for pagination...<!--nextpage--> tag and that's why I need to disable canonical url in "paginated pages" as at the bottom of mother page I have some important links that because of pagination will appear on latest child page only and robots will not reach them anymore.

    Thank you,

    Mario

    Posted 4 years ago #
  6. Sorry, I can't advise anyone to make an edit like this to the parent theme. In order to start a child theme all you need to do is move thematic_sample_child_theme folder in the thematic them directory one level up to the themes directory and activate it in the

    admin>appearance >themes

    If you are totally stubborn like I can be sometimes you could add your solution to the thematic functions.php but I absolutely do not recommend that you do that.

    Even if you have heavily customized the parent theme it would be wiser to stop now and use this forum to get help migrating those edits to a child theme than to keep moving in a direction that is explicitly *not* recommended by the creators of this framework.

    As for my post above, unfortunately using a conditional template tag will not work for paged posts or pages it will work only for paged archives. It could be done by detecting pagination in the query. So do you want to remove the canonical link from the final page of the paginated: post or page or both?

    Posted 4 years ago #
  7. mpanda
    Member

    No problem Gene I understand your position and policies of this forum.
    I will open a thread on how to massively export my current mother theme to a child one. (if it's realistically possible to do that like "save as" style)
    I guess it would be not an hard task, at least for who is smart with Thematic (not me of course as I'm absolute newbie to scripts)

    "do you want to remove the canonical link from the final page of the paginated: post or page or both?"
    I'd need to remove canonical from all but the first page (no post), as bot need to go deep in pagination up to the last page.

    Thank you,

    Mario

    Posted 4 years ago #
  8. Ok my earlier code was flawed and did not properly target paged pages >1

    I believe this does it with compatibility from WP 2.8.6 + Thm 0.9.5.1 and greater.

    function remove_thm_canonical($thm_canonical_link) {
            global $page;
    
    	/* remove canonical for paged pages > 1 */
    	if ( is_page() && $page > 1 ) {
    		// remove action for  WP 2.9+ function
    		remove_action( 'wp_head', 'rel_canonical' );
    		// empty Thematic's canonical link
    		$thm_canonical_link = null;
    	}
    	/* if WP 2.9 function exists empty Thematic's
                            canonical link to prevent duplicate link*/
    	if ( function_exists ('rel_canonical') ) {
    		$thm_canonical_link = null;
    	}
            return $thm_canonical_link;
    }
    add_filter('thematic_canonical_url', 'remove_thm_canonical');
    Posted 4 years ago #
  9. mpanda
    Member

    Hi Gene,

    your code works flawless! :))))

    Excellent job my friend, all my gratitude to you and to this forum!

    Mario

    Posted 4 years ago #
  10. Gene,

    thanks a lot for your help. I'll deprecate the function with the next release (requires >= 2.8.x).

    Chris

    Posted 4 years ago #
  11. mpanda
    Member

    Hi Gene,

    to have a complete canonical tag free paged page I also need to disable platinum seo plugin in such a page as by default it generates canonical url tag against your code in function.php.

    Unfortunately where a disable platinum it will result no meta tags in source's page and that's not seo friendly at all.

    My first solution could be to add a few descriptive H1 text immediately after every <nextpage> tag as it will display below the page's title like a description.
    I tested it and Thematics will report such a H1 text in source like "<div class="entry-content"> after "<h1 class="entry-title">".
    Basically it works. It's not the most effective seo solution but it's better then nothing.
    Ideally the cleanest solution would be to tell Thematics to supply meta description and meta title where I cannot use seo plugin in paged pages.
    I wonder if there's a function to do that similar the code to remove canonical url tag.

    Thanks,

    Mario

    Posted 4 years ago #
  12. Just uncheck the Canonical URL box in SEO Platinum's Option page in the admin. Doing so should have no effect on what we've already done here.

    Posted 4 years ago #
  13. mpanda
    Member

    Yes Gene, I did it that way but where I disable platinum in paged pages options I loose all meta tags, title and description included.
    So ideally I would tell Thematic to generate those meta tags in the event of paged pages, in order to overcome the lack of seo plugin.
    Maybe I'm asking too much to theme features.

    Thanks,

    Mario

    Posted 4 years ago #
  14. I did not mean for you to disable it in the "Edit Page" area. There is a "Platinum SEO" Options Tab right below "Settings" in the WP admin left navigation.

    There you can simply tell it not to add the canonical link by unchecking the checkbox labeled "Canonical URLs:"

    Posted 4 years ago #
  15. mpanda
    Member

    Ah ok, now I got your strategy :)
    You probably mean this: as Thematic will create canonical tag by default, there we don't need a duplicate one by platinum.
    Just in paged pages we won't canonical tag at all so there we'll keep just meta tags by platinum.

    I cover you at all Gene! :)

    Thank you

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.