How to add onload to the body using Genesis add_filter

We puzzled about this one for a while but worked out a hack that seems to work although we would appreciate it if anyone can comment with the right way to do it.

We need to add onload="initialize()" to our body tag to enable the Google map API to work.

We came across the

add_filter( 'body_class', 'add_body_class' );

and gave that a try.

Unfortunately the line

$classes[] = 'onload="initialize()"';

resulted in the following:


As it just added it to the list of body classes already in there.

Our sneaky workaround was this:

classes[] = '" onload="initialize()';

Which basically closes off the preceeding classes and adds our onload then uses the original ” from the class list to lose our onload off.

Does it work? Yes it does, but we do feel a little dirty ;-)

Wrapping a Blog post in a div

How to wrap a WordPress Blog post in a div using the Genesis Framework

We needed to wrap our blog posts in a div after the post_info but before the H2 title so we could add styling. As you can see we have our date icon separate from the main blog post and we wanted to apply a background colour to the post but not the date part of it.

In the end we didn’t bother but this is how we went about opening a new div after the post info but before the post title.

Here is our solution:

We use the Genesis Framework on top of WordPress and added a new function before the post title with an opening div.

//Add opening div before the post title
add_action( ‘genesis_before_post_title’, ‘custom_post_div’, 15 );
function custom_post_div() {
echo ‘</pre>
<div class="post_body"><!– start .post_body–>’;

Add the filter to the post_meta with a closing div.
/** Customize the post meta function */
add_filter( ‘genesis_post_meta’, ‘post_meta_filter’ );
function post_meta_filter($post_meta) {
if ( !is_page() ) {
$post_meta = ‘</div>
<!– end .post_body–></pre>
<div class="clear"></div>
return $post_meta;

This works nicely and now wraps the content, including the title and post meta in a class called post_body enabling us to style it.

You may also find our post: How to add an extra CSS file to your Genesis Framework useful as it details how to use a PHP function to add another custom .css file so you can keep all of your edits in one place.

Calculating the day number in PHP

We’ve packed several dynamic areas into our footer. You may have noticed some of them or perhaps none, I mean who actually looks at a website footer?


We love coffee, it helps get motivated and ready for the chaos that is our normal day (by the way, did I mention we have three young children)…

Our footer uses a script to calculate the total number of days since January the 1st and then multiples it by 2 as we are creatures of habit here and on average drink two cups of coffee a day.

The PHP code we use to work all this out uses the normal PHP function date(“z”) + 1 then multiples it by 2

$dayNumber = (date("z") + 1)*2;

Then we write it out to the screen:

echo $dayNumber.'<br />';