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 badges2 Answers
Reset to default 3The 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">';
}