• Resolved rinh

    (@rinh)


    Hi!

    I’m not sure this is the correct place to ask for this, but I’m just getting into block themes and I used this plugin to create a blank theme (great plugin by the way!) so I’ll try here.

    In classic themes I have ‘data-theme’ added to the html root, by editing header.php, looking like this:

    <!doctype html>
    <html data-theme="dark" <?php language_attributes(); ?>>

    How can I achieve this in block themes?

    Thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hey there @rinh

    @welcher provided this function that you can add to your child theme’s functions.php file. Create Block theme doesn’t provide this file by default, but you can create one in a code editor and add it to your child theme folder.

    add_filter(
    	'language_attributes',
    	function( $output ) {
    		return $output . ' data-theme="dark"';
    	},
    );

    Just keep in mind that it’s a little hacky. But I just tested it, and it worked for me, outputting this on the front end:

    <html lang="en-US" data-theme="dark">

    Let me know how it goes!

    Thread Starter rinh

    (@rinh)

    Works great, thank you!

    Moderator Kathryn Presner

    (@zoonini)

    You’re very welcome, glad to hear!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need to add html data-theme=”dark”’ is closed to new replies.