Hello reader's, today we discuss about "wp_head() and header.php".
Two Important and key things to add to a WordPress theme are the wp_head and wp_footer functions. These two functions are known as action hooks. Action hooks are placeholders where code is dynamically added to a theme.
-->So to add the wp_head function correctly to your WordPress theme, you have to simply open your themes header.php file and add the following line of PHP code right before the closing head tag.
<?php wp_head(); ?>
-->To correctly add the wp_footer function to your WordPress theme, open the themes footer.php file and add the following line of PHP code at the very bottom of the page:
<?php wp_footer(); ?>
-->Theme header is a set of simple html tag code.
A header "must" have some things, this template that I've made does the following (on the next steps I'll talk about each):
- Doctypes
- Conditionals to IE8, 7, 6
- Meta Tags to ensure that your theme is rendered properly
- Favicon, RSS and Pingback
- Title
- Following official WordPress guidelines, adding scripts and styles with wp_enqueue_script and wp_enqueue_style functions
- Optimized with the use of constants and removing Meta Generator tag to assist with security
- Clean and commented code
Example of header.php:-
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 8]><!--> <html <?php language_attributes(); ?>> <!--<![endif]-->
<head>
<!--=== META TAGS ===-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="description" content="Keywords">
<meta name="author" content="Name">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--=== LINK TAGS ===-->
<link rel="shortcut icon" href="<?php bloginfo('template_url');?>/path/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS2 Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<!--=== TITLE ===-->
<title><?php wp_title(); ?> - <?php bloginfo( 'name' ); ?></title>
<!--=== WP_HEAD() ===-->
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="header">
<div id="headerimg">
<h1>
<a href="<?php echo get_option('home'); ?>">
<?php bloginfo('name'); ?></a>
</h1>
<div class="description">
<?php bloginfo('description'); ?>
</div>
</div>
</div>
0 Comment(s)