【问题标题】:Wordpress shortcode not rendering in Yoast og:titleWordpress 简码不在 Yoast og:title 中呈现
【发布时间】:2022-12-31 10:48:53
【问题描述】:

我有一个简单的简码,用于帖子标题:

add_shortcode('year', 'year_shortcode');
function year_shortcode() {
    $year = date('Y');
    return $year;
}

add_filter( 'single_post_title', 'my_shortcode_title' );
add_filter( 'the_title', 'my_shortcode_title' );
add_filter('wpseo_title', 'my_shortcode_title');
add_filter( 'wpseo_metadesc', 'my_shortcode_title' );

function my_shortcode_title( $title ){
    return do_shortcode( $title );
}

它工作正常,但我突然意识到 Yoast 创建了一个 og:title 并且它不会在那里呈现(意味着它不会在 Facebook 或 whatsapp 上呈现)

我搜索了一个答案,但找不到任何东西。 有没有人遇到过这个?

也许我需要通过某种过滤器运行 og:title 这也很好,问题是如何。

提前致谢。

【问题讨论】:

  • 大概你问过 Yoast 支持这个问题。那应该是你的第一站。
  • 好的ides,刚刚在支持页面上发送了一个问题。谢谢

标签: wordpress shortcode yoast


【解决方案1】:

我用过这个,它大部分都有效。 它将更新 Yoast 中的 og:title 和 socials 等。

它不会更新 Yoast 的默认架构输出。这可能需要他们解决。

// Create Year shortcode to replace with current year.
add_shortcode( 'currentyear', 'current_year' );
function current_year() {
    $year = date( 'Y' );
    return $year;
}
// Activate shortcode function in Post Title.
add_filter( 'the_title', 'do_shortcode' );
add_filter( 'single_post_title', 'do_shortcode' );
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_title', 'do_shortcode' );
add_filter( 'wpseo_opengraph_desc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_site_name', 'do_shortcode' );
add_filter( 'wpseo_twitter_title', 'do_shortcode' );
add_filter( 'wpseo_twitter_description', 'do_shortcode' );
add_filter( 'the_excerpt', 'do_shortcode' );

【讨论】:

    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    相关资源
    最近更新 更多