Necessary child theme file set-up.

resolved (19 posts) (8 voices)

  1. olindacat
    Member

    I have spent the past few days working on a site using Modular and am realizing that it is probably a good idea to have a child theme schema as opposed to just editing theme files, or is this wrong?

    Should I child this theme now? Is it too late? I have only changed the background image, and used the theme's own dashboard/control panel to configure so far.

    I have had child themes that didn't 'take' changes to the styles.css file, and others, and I know there are many reasons why that are beyond my skill level.

    So, should I child this, if so, what are the best files to create for the child? Like, for example, the header.php? I want to modify this, as an example. (Sorry if this seems nobbish.)

    Posted 5 years ago #
  2. Elliott
    Support

    Hello olindacat,

    A child theme is a smart idea. See here, http://mysitemyway.com/docs/index.php/Using_Child_Themes.

    Posted 5 years ago #
  3. olindacat
    Member

    Hi Elliot,

    Is it too late to make one? (I have made 'some' mods but not many. Will it complicate things or will everything still work normally? Which files should I create? I am using 'blue.css' skin with a BG image.

    Thanks for doing such a good job supporting this site.

    John

    Posted 5 years ago #
  4. olindacat
    Member

    Never mind. That was a very helpful article. Thanks, Elliot.

    Posted 5 years ago #
  5. Hi John,

    Let us know if you need anything else!

    []'s

    Posted 5 years ago #
  6. bynatasha
    Member

    Hi!

    I created a child theme for method. Here's my top text:

    /*
    Theme Name: Method Child
    Theme URI:
    Description:
    Author:
    Author URI:
    Template: method
    Version: 1.8
    */

    @import url('../method/style.css');

    The problem is that my child theme is overwritten by the original style.css!

    Did I make something wrong?

    Posted 4 years ago #
  7. Elliott
    Support

    If you add CSS to the child theme stylesheet then it will be displayed at the very end so it should be overriding the parent stylesheets.

    You can also use the !important rule to override any CSS.

    Posted 4 years ago #
  8. bynatasha
    Member

    I have added my CSS. That's the reason I'm saying it's overwritten.

    That means that I'll have to use !important to all my code. Is that normal?

    Posted 4 years ago #
  9. Elliott
    Support

    It depends on the CSS but yes it's fine to use.

    Posted 4 years ago #
  10. Is there any way you can make a child theme fully functional withouth having to select and activate a customized style in the theme options panel?

    I have a MrMasterKey child theme, but at the moment I still upload a MrMasterKey.css file to the [parent_theme]/styles folder and activate it. Would love to do without it.

    Any hints, Elliott or Rochester?

    TIA,

    Helmar

    Posted 4 years ago #
  11. Elliott
    Support

    No, not that I know of. I would try asking here, http://wordpress.org/support/, to see if anyone has done that before.

    Posted 4 years ago #
  12. Hi Elliott,

    I'm puzzled. Why ask at WP support, when it is a clear MSMW framework issue .- at least in my view. If I activate a child theme, any CSS file in the child theme folder should overwrite the settings given in the parent folder. Isn't the whole point of a child theme that you keep the parent clean of any modifications? Just wondering, and perhaps this could be built into a future version of the framework with relative ease.

    cheers,

    Helmar

    Posted 4 years ago #
  13. Elliott
    Support

    If you add the CSS in the child theme style.css file then yes it should. Just adding extra stylesheets in the child theme folder is not going to do anything unless you import them in the main style.css file.

    And make sure to add them below the line where you import the parent theme stylesheet.

    Posted 4 years ago #
  14. AskYvi
    Member

    I followed your instructions for childthemes but adapted WP's new recomendation to not use @import but use:

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

    }

    and in my awake-childtheme no changes are being displayed?! No matter if I change something in the skin or costum css, it doe not update.

    Any help would be appreciated

    Posted 2 years ago #
  15. I'm moving to the new enqueue way for child themes, too, and would love to know he response to AskYvi's question.

    Posted 2 years ago #
  16. water-works
    Member

    I am also looking to build a child theme. I'm going to be using Wordpress' recommendation for enqueue and avoid the @import which is no longer considered good practice.

    Posted 2 years ago #
  17. water-works
    Member

    No response on this yet? Still looking to get child theme working.

    Important to note:
    Using the @import is suggested by MSMW
    http://mysitemyway.com/docs/Using_Child_Themes

    However, using @import is no longer suggested by Wordpress
    https://codex.wordpress.org/Child_Themes

    "The final step is to enqueue the parent and child theme stylesheets. Note that the previous method was to import the parent theme stylesheet using @import: this is no longer best practice. The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme's functions.php. You will therefore need to create a functions.php in your child theme directory."

    Wordpress also states:
    "The following example function will only work if your Parent Theme uses only one main style.css to hold all of the css. If your theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies."

    MSMW themes typically use multiple style sheets since it's possible to create a custom CSS sheet within the admin area for the theme. Then how do we set up our functions.php to make sure we maintain all of the Parent Theme dependencies as Wordpress suggests?

    Child theme with multiple dependencies:
    https://wordpress.org/support/topic/theme-flexible-multiple-css-enqueue-for-child-theme

    Further discussion and solutions for child theme with multiple dependencies:
    http://wordpress.stackexchange.com/questions/163301/versioning-import-of-parent-themes-style-css

    Perhaps MSMW can update their suggestions for how to build a child theme properly using Wordpress' most recent best practices rules for child themes. Thanks. :)

    Posted 2 years ago #
  18. water-works
    Member

    Update. I got my child theme to work for Dejavu theme, after much internet searching. The following is the code for my functions.php. Note, this works for adding custom css styles. I have not yet tried making edits to theme files such as header.php, footer.php etc.

    Creating child theme edits for framework.php.
    http://mysitemyway.com/support/topic/activate-new-php-in-child-theme#post-51637

    Redeclaring functions
    http://mysitemyway.com/docs/Using_Child_Themes#Redeclaring_functions

    <?php
    
    function use_parent_theme_stylesheet() {
        // Use the parent theme's stylesheet
        return get_template_directory_uri() . '/style.css';
    }
    
    function my_theme_styles() {
        $themeVersion = wp_get_theme()->get('Version');
    
        // Enqueue our style.css with our own version
        wp_enqueue_style('child-theme-style', get_stylesheet_directory_uri() . '/style.css',
            array(), $themeVersion);
    }
    
    // Filter get_stylesheet_uri() to return the parent theme's stylesheet
    add_filter('stylesheet_uri', 'use_parent_theme_stylesheet');
    
    // Enqueue this theme's scripts and styles (after parent theme)
    add_action('wp_enqueue_scripts', 'my_theme_styles', 20);
    
    ?>

    Explanation of functions.php code shown above
    http://wordpress.stackexchange.com/questions/163301/versioning-import-of-parent-themes-style-css/182023#182023

    Explanation/debate on including a closing php tag for functions.php
    https://wordpress.org/support/topic/functionsphp-in-a-child-theme

    Posted 2 years ago #
  19. water-works
    Member

    Update. The above code seems to work perfectly for child theme for theme Dejavu. I have not tested it out with other themes as I have purchased only the the Awake and Dejavu themes.

    If you're stuck on how to make edits to theme files within your child theme, I followed the rules provided by MSMW regarding redeclaring functions.

    Redeclaring Functions
    http://mysitemyway.com/docs/index.php?title=Using_Child_Themes

    Important to note is that a lot of code happens within the /[theme-name]/lib/functions/theme.php file. Quite often if you want to make edits to the theme, you'll need to cut-and-paste code from the theme.php to your /[theme-name]-child/functions.php. Be sure to place the cut-and-pasted code after the initial code to enqueue style sheets. Then edit the code within your /[theme-name]-child/functions.php to do what you want it to do and it will override original function located at /[theme-name]/lib/functions/theme.php.

    Hopefully this helps someone else who might be stuck on child themes for Dejavu or the other themes.

    Posted 2 years ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme