yeast seo产品标题中的运输类别

我正在尝试在产品页面的标​​题元标记中添加运输类别名称

我使用yoast seo插件

并找到此代码来创建自定义变量

但是当我尝试根据运输类别设置标题时,网站崩溃了

  function get_namex() {
    return '(Estimated Delivery in 7-15 days)';
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {

        global $product;
    $defined_shipping_class = "Estimated Delivery in 7-15 days";

    // Get the product shipping class WP_Term Object
    $term = get_term_by( 'slug',$product->get_shipping_class(),'product_shipping_class' );

    if( is_a($term,'WP_Term') && $term->name == $defined_shipping_class ){
    wpseo_register_var_replacement( '%%namex%%','get_namex','advanced','some help text' );
    }


}
// Add action
add_action('wpseo_register_extra_replacements','register_custom_yoast_variables');

我尝试了许多其他方法,但在使用$ product-> get_shipping_class()时总是崩溃

示例我正在尝试实现的目标 if是产品页面,并且如果运送类= X,则将运送类的名称添加到产品页面的元标题中

这也会使我的网站崩溃

 function register_custom_yoast_variables() {

    $product = wc_get_product();
    $shipping_class = $product->get_shipping_class();

  $test1 = "namex";
if (  ($shipping_class == $test1 ) )  {
    wpseo_register_var_replacement( '%%namex%%','some help text' );

    }


}

感谢您的帮助

zwx917 回答:yeast seo产品标题中的运输类别

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167522.html

大家都在问