php Yoast SEO规范输出的代码片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Yoast SEO规范输出的代码片段相关的知识,希望对你有一定的参考价值。

<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Remove Yoast SEO Canonical From Search Pages Only
 * Credit: Yoast Team
 * Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8
 */

add_filter( 'wpseo_canonical', 'yoast_remove_canonical_search' );

function yoast_remove_canonical_search( $canonical ) {
	if( is_search() ) {
		return false;
	} else {
		return $canonical;
	}
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Remove Yoast SEO Canonical From Individual or Multiple Items
 * Credit: Yoast Team
 * Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8
 *********
 * DIFFERENT POST TYPES
 * Post: Change 123456 to the post ID
 * Page: Change is_single to is_page and 123456 to the page ID
 * Custom Post Type: Change is_single to is_singular and 123456 to the 'post_type_slug'
    Example: is_singular( 'cpt_slug' )
 *********
 * MULTIPLE ITEMS
 * Multiple of the same type can use an array.
    Example: is_single( array( 123456, 1234567, 12345678 ) )
 * Multiple of different types can repeat the if statement
 */
 
add_filter( 'wpseo_canonical', 'yoast_remove_canonical_items' );

function yoast_remove_canonical_items( $canonical ) {
  if ( is_single ( 123456 ) ) {
    return false;
  }
  /* Use a second if statement here when needed */
	return $canonical; /* Do not remove this line */
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Remove Yoast SEO Canonical From All Pages
 * Credit: Yoast Team
 * Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8
 */

add_filter( 'wpseo_canonical', '__return_false' );

以上是关于php Yoast SEO规范输出的代码片段的主要内容,如果未能解决你的问题,请参考以下文章

php 在Yoast SEO中更改或删除OpenGraph输出的代码片段。此代码中有多个代码段。

php Yoast SEO站点地图的过滤器和示例代码

php 删除或修改Yoast SEO prev或下一个URL。只复制您需要的代码部分。

php Yoast SEO机器人或WP robots.txt的过滤器和示例代码

php 使用Yoast SEO Analyis插件时,将ACF字段添加到Yoast SEO权重中

php 改变Yoast SEO默认图像大小