Skip to:
Content
Pages
Categories
Search
Top
Bottom

Child Theme – How to partially inherit the default theme’s CSS

  • Avatar of faramarz
    Faramarz
    Participant

    @faramarz

    I created/activated a child-theme for my bp-default theme. This article helped me but somehow I can’t figure out how to inherit the parent’s CSS and also modify some of the existing CSS with my style.css in my child theme folder when needed. I don’t want to make any changes to my parent bp-default theme and that’s the whole idea for creating a child theme.

    For example, the theme’s default width is 1250px and when I add the code below to my style.css nothing changes and the default value from the parent theme overrides my custom value:

    body {
    	max-width: 960px;
    }

    As article suggested, I added this to my header.php in my child theme folder:
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    By the way, as of now, my child theme only contains two files, style.css and header.php.

    But yet still my CSS change doesn’t work. It only works if I add !important to my max-width value. Does this mean that I have to add !important to every code I modify in my style.css? That doesn’t make sense to me and that’s not how WordPress child themes work. There should be another way. I think I am missing something.

    Thanks

Viewing 1 replies (of 1 total)
  • Avatar of Henry
    Henry
    Participant

    @henrywright-1

    The easiest way to inherit ‘some’ of the CSS from the default theme is to copy what you need and paste it into your theme’s style.css.

    Then add this to your functions.php file

    if ( !function_exists( 'bp_dtheme_enqueue_styles' ) ) :
        function bp_dtheme_enqueue_styles() {}
    endif;

    This will tell BuddyPress not to queue up the default stylesheet.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.