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

Posted

tags:

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

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

/* Remove Individual Yoast SEO OpenGraph meta tags
 * Credit: Yoast Development team
 * Last Tested: Jul 28 2017 using Yoast SEO 5.1 on WordPress 4.8
 */

add_filter('wpseo_opengraph_url' , '__return_false' );
add_filter('wpseo_opengraph_desc', '__return_false' );
add_filter('wpseo_opengraph_title', '__return_false' );
add_filter('wpseo_opengraph_type', '__return_false' );
add_filter('wpseo_opengraph_site_name', '__return_false' );
add_filter('wpseo_opengraph_image' , '__return_false' );
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Remove Yoast SEO OpenGraph Output From One Post/Page
 * Credit: Unknown
 * Last Tested: Apr 01 2017 using Yoast SEO 4.5 on WordPress 4.7.3
 *********
 * 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, 234567, 345678 ) )
 * Multiple of different types can repeat the if statement
 */

add_action('wp_head', 'remove_one_wpseo_og', 1);

function remove_one_wpseo_og() {
  if ( is_single ( 123456 ) ) {
    remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), 30 );
  }
    /* Use a second if statement here when needed */
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Remove All Yoast SEO OpenGraph Output
 * There is an on/off switch in the plugin Admin > SEO > Social > Facebook
 * Credit: Unknown
 * Last Tested: Apr 01 2017 using Yoast SEO 4.5 on WordPress 4.7.3
 */

add_action('wp_head', 'remove_all_wpseo_og', 1);

function remove_all_wpseo_og() {
  remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), 30 );
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Change Yoast SEO OpenGraph type
 * Credit: Yoast Team
 * Last Tested: Jul 11 2017 using Yoast SEO 5.0.1 on WordPress 4.8
 */

add_filter( 'wpseo_opengraph_type', 'yoast_change_opengraph_type', 10, 1 );

function yoast_change_opengraph_type( $type ) {
  /* Make magic happen here
   * Example below changes the homepage to a book type
   */
  
  if ( is_home() ) {
    return 'book';
  } else {
    return $type;
  }
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Enforce HTTP Open Graph URLs in Yoast SEO
 * Credit: stodorovic https://github.com/stodorovic
 * Last Tested: Feb 06 2017 using Yoast SEO 4.2.1 on WordPress 4.7.2
 */
 
add_filter( 'wpseo_opengraph_url', 'my_opengraph_url' );

function my_opengraph_url( $url ) {
        return str_replace( 'https://', 'http://', $url );
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Change Open Graph image URLs in Yoast SEO
 * Credit: Yoast Development team
 * Last Tested: Jul 04 2018 using Yoast SEO 7.7.3 on WordPress 4.9.6
 */

add_filter( 'wpseo_opengraph_image', 'change_opengraph_image_url' );

function change_opengraph_image_url($url) {
    return str_replace('current_domain.com', 'new_domain.com', $url);
}

以上是关于php 在Yoast SEO中更改或删除OpenGraph输出的代码片段。此代码中有多个代码段。的主要内容,如果未能解决你的问题,请参考以下文章

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

php 从Yoast SEO Video中删除Yandex标签

php Yoast SEO删除面包屑链接

php Wordpress:过滤管理员列并删除yoast seo列

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

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