Site logo

[Resolved] Adding attributes to body tag using from a custom page template

Home Forums Support [Resolved] Adding attributes to body tag using from a custom page template

Home Forums Support Adding attributes to body tag using from a custom page template

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #2508439
    David
    Staff
    Customer Support

    No, in Fernandos code you leave it like that.

    #2508451
    Vincenzo

    Ok. Now I got it.

    #2508521
    David
    Staff
    Customer Support

    Glad to hear that

    #2535457
    akal

    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

    #2535793
    David
    Staff
    Customer Support

    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 );
    #2536032
    akal

    Perfect ! Thank you ^^
    akal

    #2536613
    David
    Staff
    Customer Support

    You’re welcome

Viewing 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.