Adding onload to body for certain pages

I am looking for a function to add

body onload=prepareFrame('https://airtable embed URL here')

to certain wordpress pages only.

I know how to add a custom body class but not an onload statement.

add_filter('body_class', 'custom_body_class');
function custom_body_class($classes) {
    global $post;
    if ($post-ID == 346) {
        $classes[] = 'services';
    }
    return $classes;
}

Topic functions php Wordpress

Category Web


You could use the body_class filter to add additional attributes. I'm not sure if this is the best option out there. Maybe javascript would be better for this.

function my_add_body_attribute($classes) {
    echo 'onload="doyourthing" ';
    return $classes;
}
add_filter('body_class', 'my_add_body_attribute');

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.