Site logo

Archived topic

Adding attributes to body tag using from a custom page template

21 replies · Started by Charles on December 19, 2022

Viewing posts 16–22 of 22

No, in Fernandos code you leave it like that.

Ok. Now I got it.

Glad to hear that

Hi David,
I've same needed and tried your code which is working (of course^^), thanks to you no need to copy header.php

Question : how could we do the same with :

<div class="site grid-container container hfeed" id="page" data-attr="data rocks"><div>

Thanks
akal

Hi there,

you can do this:

add_filter( 'generate_after_element_class_attribute', function( $attributes, $context ) {
    if ( 'page' === $context ) {
        $attributes .= ' data-attr="data rocks"';
    }

    return $attributes;
}, 20, 2 );

Perfect ! Thank you ^^
akal

You're welcome

This archived topic is closed to new replies.