Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • wp_head() and header.php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 562
    Comment on it

    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):

    1. Doctypes
    2. Conditionals to IE8, 7, 6
    3. Meta Tags to ensure that your theme is rendered properly
    4. Favicon, RSS and Pingback
    5. Title
    6. Following official WordPress guidelines, adding scripts and styles with wp_enqueue_script and wp_enqueue_style functions
    7. Optimized with the use of constants and removing Meta Generator tag to assist with security
    8. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: