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

html - Applying metatag to single page

programmeradmin0浏览0评论

I want to change the viewport metatag for a single page on my website. I want the rest of the website to adhere to the following:

<meta name="viewport" content="width=device-width, initial-scale=1">

But I want one particular page (id=7730) to adhere to this:

<meta name="viewport" content="width=device-width, initial-scale=0">

Any help is greatly appreciated - I'm a backend/html/php beginner, so layman's terms are helpful!

I want to change the viewport metatag for a single page on my website. I want the rest of the website to adhere to the following:

<meta name="viewport" content="width=device-width, initial-scale=1">

But I want one particular page (id=7730) to adhere to this:

<meta name="viewport" content="width=device-width, initial-scale=0">

Any help is greatly appreciated - I'm a backend/html/php beginner, so layman's terms are helpful!

Share Improve this question asked Mar 3, 2020 at 15:57 ClearlyGeorgeClearlyGeorge 34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use the WordPress conditional tags to accomplish this. Both is_page() and is_singular() should work, you just need to pass a slug, or in your case, an ID. Then we can use the wp_head hook to conditional add in the meta tag.

You can add the following function and hook into your functions.php file.

/**
 * Conditionally add metatag to specific page
 * 
 * @return void
 */
function wpse359922_metatag_conditional() {

    if( is_page( 7730 ) ) {
        echo '<meta name="viewport" content="width=device-width, initial-scale=0">';
    } else {
        echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
    }

}
add_action( 'wp_head', 'wpse359922_metatag_conditional' );

On a side-note, your whole website should be mobile friendly otherwise it will get dinged on SEO by engines like Google and Bing.

发布评论

评论列表(0)

  1. 暂无评论