Web Design using the Genesis Framework

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:

onload="initialize()"">

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

2 replies
  1. Brett
    Brett says:

    Yep, I’m seeing the same problem as Daniel. This has at least gotten me into the ball park, but I have dangling classes as well and the unload event is not loading.

    Still digging….

    Reply
  2. Daniel
    Daniel says:

    My problem is that my theme is adding classes after I added my onload statement.

    I end up with classes hanging after the onload statement

    Reply

Leave a Reply

Your e-mail address will not be published. Required fields are marked *