Support » Theme: Twenty Twenty » Questions for child theme – Remove inline styles & mix content with title

  • Hello there,
    thanks for your work on this theme. I was hoping I could get a little assistance here.

    I am creating a child theme based on Twenty Twenty and I am wondering if there is any way to remove the inline styles it produces? I want to be able to set my colors in CSS and never have to use !important. I tried the solution proposed here, but it does not work for me.

    My second question is a bit hard to explain. All I really want is to be able to put some content in a div with the page title, and have that div end before the rest of the content begins. The trick is ending that div. By default, the title is in a div that contains all the other content divs, and I’d rather have it in a div that ends before the content divs, but still be able to add some content into it… does that make sense?

    Or alternatively I’d just need to get rid of the H1 from the theme and have a way to put the H1 back into the page in a full-width group block. However.. that seems a bit hacky? (Edit: just because, if the content editor did not remember to add the H1 back in, the page would not have an H1, which is bad form)

    I’d also thought of using Advanced Custom Fields for this and having a separate field for the stuff that goes in the header… but I wanted to see if there was a more standard solution first.

    Thanks a bunch in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • I plugged that code in that thread into both the functions.php file of the default TwentyTwenty theme as well as my child theme separately and it removed the inline styling from the <head> tag assuming that is what you’re referring to?

    <style id="twentytwenty-style-inline-css">

    Regarding the H1 div stuff, not really sure what you mean. Do you have a sample of the HTML elements that are currently being output by the theme and a sample of what you want them to look like?

    Thread Starter FrogDesk Strategy


    Thanks for your response!

    Does this image make my question regarding page sectioning any clearer?

    I have included this in my child theme’s function.php and it has no effect. The twentytwenty-style-inline-css is still included. It’s pretty much a brand new child theme on a wholly unmodified Twenty Twenty. The only other thing in function is enqueueing the CSS. This is the entire functions.php:

    add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_parent_styles' );
    function mytheme_enqueue_parent_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    add_action( 'wp_enqueue_scripts', function() {
    	$styles = wp_styles();
    	$styles->add_data( 'twentytwenty-style', 'after', array() );
    }, 20 );

    I took your code and placed it inside of my child theme’s functions.php file with just that code and I get this output in <head> on my child theme

    <link rel="stylesheet" id="parent-style-css" href="http://localhost:81/wp-content/themes/twentytwenty/style.css?ver=5.3.2" media="all">
    <link rel="stylesheet" id="twentytwenty-style-css" href="http://localhost:81/wp-content/themes/2020child/style.css?ver=5.3.2" media="all">
    <link rel="stylesheet" id="twentytwenty-print-style-css" href="http://localhost:81/wp-content/themes/twentytwenty/print.css?ver=5.3.2" media="print">

    If I remove the second add_action in the code that is supposed to take out the inline styling I get this

    <link rel="stylesheet" id="parent-style-css" href="http://localhost:81/wp-content/themes/twentytwenty/style.css?ver=5.3.2" media="all">
    <link rel="stylesheet" id="twentytwenty-style-css" href="http://localhost:81/wp-content/themes/2020child/style.css?ver=5.3.2" media="all">
    <style id="twentytwenty-style-inline-css">...</style>
    <link rel="stylesheet" id="twentytwenty-print-style-css" href="http://localhost:81/wp-content/themes/twentytwenty/print.css?ver=5.3.2" media="print">

    So it is working for me. Do you have any plugins active? If so, try deactivating them all. It could also possibly be a caching issue. Try visiting in your browser and see if that fixes it. Or you can also use a private/incognito browsing window.

    If that doesn’t work, ensure that your hosting provider doesn’t have some type of server caching active. If they do, if you can clear that, try that and see if the inline styling goes away then.

    Regarding the image, it sort of does. Are you wanting this on a single post/page URL on the site or the homepage?

    When on a single post URL, there is a <header> element that contains the post categories, the post title in an H1 along with the post meta such as the publish data, author and comments.

    After that <header> element there is the <div class="post-inner thin"> element that contains the rest of the post content. I’m guessing you want more control over what is displayed within the <header> element though? Instead of just what is inserted automatically from what the theme is coded for?

    Thread Starter FrogDesk Strategy


    Ah, well, my apologies. Not sure what I was doing wrong last night but the inline style removal works now. Excellent.

    About the header structure… I want this on every page. The <header> element ends before the content begins. I need a way of putting some content inside that header so that it can share a background image or gradient with the page title. For example, I want on one page to put a video and a small text blurb to be in there, as a way of introduction and highlighting some of the most important bits on the page. On another page it might just be a blurb of text, or an image.

    It seems like something a lot of sites do so maybe I’m conceptualizing it wrong and overlooking some really simple solution? I always seem to run into a pretty similar issue whenever I make themes for WordPress, the page title just seems to be mandated as completely separate from the post content?

    Thank you so much for your time and assistance.

    Thread Starter FrogDesk Strategy


    Thinking about it, a cool way to do it would be if the page title in Gutenberg could be dragged around like a normal header block, and placed at will, but not deleted. That would solve this issue elegantly.

    But this of course would be completely out of scope for solving here, I was just wondering if anyone had a solution to the problem specific to Twenty Twenty.

    Glad to hear you got the inline styling fixed.

    Don’t have much suggestions regarding the content other than maybe using Gutenberg to handle full control and essentially just have the theme as an empty template. Somebody else may come along with more input though.

    Thread Starter FrogDesk Strategy


    I’m going to just go with removing the H1 from the template and expecting every page to add its own H1. Hopefully it won’t cause any issues with pages that don’t have H1s but I can’t see any other way that isn’t a whole ordeal.

    Thanks so much for your assistance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Questions for child theme – Remove inline styles & mix content with title’ is closed to new replies.