Add header / footer in wordpress

Add this to the functions.php

function function_name() {
?>
whatever you want to print
<?php
}
add_action( 'wp_footer', 'function_name' );


function function_name() {
?>
whatever you want to print
<?php
}
add_action( 'wp_head', 'function_name' );

One thought on “Add header / footer in wordpress

  1. admin says:

    If you want to selectively run code by page ID do this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function some_func() {
    if(get_the_ID()== 1111){
    ?>
     <script type='text/javascript'>
            jQuery(window).load(function () {
          /*run any js code you want..etc.*/
          setTimeout(function(){jQuery('[name=somename]').val('somevalue')},500);
        });
     </script> 
    <?php
    }
    }
    add_action( 'wp_footer', 'some_func' );

    Important note: The get_the_ID() must be inside the function for it to work. It doesn’t work outside because ID not loaded yet in WP at that point.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>