Removing rel canonical added by Yoast SEO plugin

南笙酒味 提交于 2019-11-29 10:05:09
nautilus7

rel="canonical" has nothing to do with crawling. It has to do with indexing and prevents the same page from indexing twice or more.

Anyway, if you still want to do this you can do it by adding this code to your functions.php:

add_filter( 'wpseo_canonical', '__return_false' );

Source: https://yoast.com/wordpress/plugins/seo/api/

You can also use this in wordpress conditional tags

Refer: https://codex.wordpress.org/Conditional_Tags

// Remove - Canonical for - [Search - Page]
function remove_canonical() {

    // Disable for 'search' page
    if ( is_search() ) {
        add_filter( 'wpseo_canonical', '__return_false',  10, 1 );
    }
}
add_action('wp', 'remove_canonical');

Remove canonical for ALL pages.

// Disable Canonical for - ALL pages
function remove_canonical() {
    add_filter( 'wpseo_canonical', '__return_false',  10, 1 );
}
add_action('wp', 'remove_canonical');

most likely the canonical is not generated by yoast, there is a wordpress inbuilt function you can prevent it by adding this to your theme´s functions.php

remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'rel_canonical');

You can also disable the canonical urls for wordpress. Look here:Desactivar rel=”canonical” de Yoast WordPress SEO o de WordPress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!