Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

We need to add two snippets of code, one right below the opening body tag, and the other right before the closing body tag. What is the best way to do this? I checked out the wp_enqueue_script, but it appears the content would be in the head section.

share|improve this question

2 Answers

Did you even open header.php and take a peek? You'll see genesis_before() called right after the opening <body> tag - follow the white rabbit and you get:

function genesis_before() { do_action('genesis_before'); }

And likewise for the footer. So...

add_action( 'genesis_before', 'my_genesis_script' );
add_action( 'genesis_after', 'my_genesis_script' );

function my_genesis_script()
{
    if ( current_filter() == 'genesis_before' )
        echo '<script>party.start();</script>';
    else
        echo '<script>if ( cops.called() ) party.split();</script>';
}
share|improve this answer

You were on the right track. wp_enqueue_script takes a parameter called in_footer which defines whether your script should be loaded before page content or at the end of the page body.

$in_footer: (boolean) (optional) Normally scripts are placed in the <head> section. If this parameter is true the script is placed at the bottom of the <body>. This requires the theme to have the wp_footer() hook in the appropriate place. Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer. Default: false

Here is the reference on codex: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.