admin管理员组

文章数量:1199762

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

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;
}
Share Improve this question asked May 4, 2022 at 17:10 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

本文标签: phpAdding onload to body for certain pages