最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

A way to export slug as meta tag

programmeradmin1浏览0评论

Is there's a standard way to expose post slug as meta tag, so it appears in HTML as say <meta name="slug" content="my-article-123">?

Is there's a standard way to expose post slug as meta tag, so it appears in HTML as say <meta name="slug" content="my-article-123">?

Share Improve this question asked Jun 17, 2020 at 15:46 Alex IvasyuvAlex Ivasyuv 1012 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I don't think there is a built-in mechanism to write meta tags, no: you have to echo it from a wp_head hook. For example:

function slug_meta_tag()
{
    if ( is_single() ) {
        global $post;
        if ( $post && $post->post_name ) {
            echo '<meta name="slug" content="' . esc_html( $post->post_name ) . '" />';
        }
    }
}
add_action( 'wp_head', 'slug_meta_tag', 10, 0 );

(I'm using the top answer here to get the slug, but there are other approaches there too.)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论