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