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 badges1 Answer
Reset to default 0You 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744700050a4588723.html
评论列表(0条)