WordPress.org

Ready to get started?Download WordPress

Forums

How to add onload="createGridder()" to the tag dynamically (2 posts)

  1. richer_image
    Member
    Posted 1 year ago #

    H all

    Title says it all really - is there a way this can be done?

    Basically I'm looking for a way to add onload="createGridder()" to the body tag so it looks like this:

    <body onload="createGridder()" class="yadda yadda">

    I'd like this to be done by editing a functions.php file as opposed to editing a template.

    Thank you in advance, Richard

  2. bcworkz
    Member
    Posted 1 year ago #

    You can't do it with php code unless your theme has a filter to alter that aspect of the html sent to the client. Highly unlikely. It really is a template thing. PHP cannot manipulate the DOM object, it only exists in the client browser.

    You could use javascript though, such as the .addEventListener method, but there are cross browser support issues complicating things. Things are easier with jQuery with something like $(document).ready(handler);

Topic Closed

This topic has been closed to new replies.

About this Topic