Tagged: child theme Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 1:15 pm on November 12, 2015 Permalink | Reply
    Tags: child theme,   

    Categories: Plugins, WordPress ( 19 )

    Child Theme Wizard – Version 1.1 released 

    wizard

    I’ve released a new version of my popular Child Theme Wizard plugin today. Everything remains the same, except for one thing: the parent theme is no longer loaded via CSS, it’s now being loaded via PHP. Let me explain why.

    When I wrote this little tool in 2014, the best practice to create a child theme was to load the parent’s style sheet via CSS. This was done with an @import statement, like this:

    @import url("parent-theme/style.css");
    

    While this approach works just fine, this is no longer regarded as the best approach to the puzzle. That’s because the parent theme’s full path is hard coded into your child theme, and should the parent theme ever change it’s folder name, your child theme would stop working.

    There’s a better way to get the same thing done by loading the parent style sheet via PHP in the functions.php file. Here’s how it’s done:

    function theme_enqueue_styles() {
    
        $parent_style = 'parent-style';
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style )
        );
    }
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    

    So that’s what the update does: switch from the older way of loading the parent theme to the new one. There. Keeping up with the times and all ๐Ÿ™‚

    Download Child Theme Wizard

    You can download the plugin from the official WordPress Plugin repository, or take a look at the source code on GitHub. Enjoy!





     
    • John McCulloch 7:59 pm on February 2, 2016 Permalink | Reply

      Mr. Versluis,

      Thank you for creating the child theme wizard. I watched your video and read the documentation associated with it, but I still don’t understand what the Child Theme URL field is referring to. Could you please explain further? Thank you,warm regards,

      John M.

      • Jay Versluis 2:56 am on February 6, 2016 Permalink | Reply

        Hi John, the URL field is a metadata field. If you take a look at your installed themes, you’ll find that the ones made by WordPress link to automattic.com – that’s the URL you put in there, one that links to your theme (say a Github page, or where or where others can download your theme). Needless to say it’s optional.

    • dutchguru 6:03 pm on March 21, 2016 Permalink | Reply

      Hello mr Jay Versluis,

      The plugin made a subdir, copied the style.css and a start for the function.php. So far so good.
      [A] I have lot of CSS made for shadow buttons and so on. But were not executed. Made the extensions by hand in the ‘normal’ style.css and it’s working. ( but I have still a few websites to go.

      [B] I made an enhancement to the footer.php, can I arrange this by coping the footer.php to the Child-directory ?

      • Jay Versluis 10:33 pm on March 21, 2016 Permalink | Reply

        Hi there! As for A, I have no idea. Anything in the child theme’s style.css should be pulled in. If it doesn’t work, I don’t know why. And B, yes indeed – you’re absolutely right: copy the footer.php (or any other amended file) into the child theme’s directory, and WordPress will load that instead of the original. As a rule of thumb, if a file is present in the child theme, it will be loaded instead of the original.

        • dutchguru 6:25 am on March 22, 2016 Permalink | Reply

          Hello, thanks for your answer.
          Regarding [B]
          if the theme author made also an enhancement in the footer.php, I’missing by copying the full file.
          What if I take this footer.php, just only my lines ….. or will it be completely overwritten ?

          • Jay Versluis 7:15 am on March 22, 2016 Permalink

            You’ll have to copy the entire file over, WordPress will replace it completely. Partial amendments only work with style.css, all other files will be overwritten completely by the child theme.

    • David Knoerr 6:44 pm on August 11, 2016 Permalink | Reply

      Your plugin worked great thank you!!! No problems.

      • Jay Versluis 11:06 pm on August 11, 2016 Permalink | Reply

        Excellent, glad to hear it. Thank you, David!

  • Jay Versluis 5:02 pm on March 13, 2014 Permalink | Reply
    Tags: child theme,   

    Categories: WordPress ( 137 )

    How to test if your theme is a Child Theme 

    wordpress-icon
    You may need to know which of your themes are child themes, or in fact if the current theme you’re using is a parent or a child theme.

    Here’s how you can test both options.

    The following code snippet will iterate through all themes that are currently installed and displays the title and if it is a child theme or not:

    $allThemes = wp_get_themes();
    echo '<ol>';
    foreach ($allThemes as $theme) {
    	echo '<li>';
    
    	// print the theme title
    	echo $theme->get('Name');
    
    	// determine whether it's a child theme or not
    	if ($theme->parent() == false) {
    		echo ' is not a Child Theme.</li>';
    	} else {
    		echo ' is a Child Theme</li>';
    	}
    }
    echo '</ol>';
    

    First we grab an array of installed themes using wp_get_themes(). Each item is an object of WP_Theme and has many helpful methods. Its method parent() will return false for non-child themes, or the parent theme if it is in fact a child theme.

    Next we test if the output is false, and if so print a status accordingly.

    Is the current theme a child theme?

    Here’s how we can check it:

    // is the current theme a child theme?
    $currentTheme = wp_get_theme();
    if ($currentTheme->parent() == false) {
    	echo 'The current theme is not a child theme.';
    } else {
    	echo 'The current theme is a child theme';
    }
    

    Here we employ very much the same, except for the first line in which we grab only a single object which defaults to the current theme.

    Check out all the other bits of info this class can provide.





     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel