$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Meta tag viewport|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Meta tag viewport

matteradmin9PV0评论

I made my very own WordPress theme from scratch and I don't use a header nor a footer for it (so no header.php or footer.php files present). All of the important content is directly in the index.php file.

So I was wondering where I can put my meta tags in. Specifically this meta tag,

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

I'm currently making my theme responsive and so far, all my css media queries are not working at all.

Can I just put it in my index.php file or do I have to set up a function in the functions.php file?

Thanks for any help!

I made my very own WordPress theme from scratch and I don't use a header nor a footer for it (so no header.php or footer.php files present). All of the important content is directly in the index.php file.

So I was wondering where I can put my meta tags in. Specifically this meta tag,

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

I'm currently making my theme responsive and so far, all my css media queries are not working at all.

Can I just put it in my index.php file or do I have to set up a function in the functions.php file?

Thanks for any help!

Share Improve this question edited May 24, 2017 at 3:03 eastwind asked May 24, 2017 at 2:34 eastwindeastwind 451 gold badge1 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

The meta tag should get inserted in the <head> section of a website. Regardless if you are using a header.php and footer.php or not, you should have a <head> section in your document.

For example the code in your document should be something like:

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">

Also make sure you are using <?php wp_head(); ?> (before closing </head> section) and <?php wp_footer(); ?> (before closing </body> section) in your theme, as nearly all plugins depend on these. As this codes are default in the header.php and footer.php files.

I guess that is no real WP question it just seems about the meta tag and section.

Try this in functions.php

add_action( 'wp_head', 'add_viewport_meta_tag' , '1' );

function add_viewport_meta_tag() {
    echo '<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">';
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far