Search code examples
wordpressthemesparent-childstylesheet

Wordpress check if theme is a child using stylesheet


I want to check if specific theme is a child theme using stylesheet.

For exmaple:

$childBoolean = functionHere( 'twentyfifteen' );

I need some kind of function that checks if specific theme is a child. It should return a boolean.

So, is there a function that ckecks it ? Any ideas ?

Thank you


Solution

  • This code might be useful if you know how to use it:

    1486                    // Look in a parent theme first, that way child theme CSS overrides.
    1487                    if ( is_child_theme() ) {
    1488                            $template_uri = get_template_directory_uri();
    1489                            **$template_dir = get_template_directory();**
    1490    
    1491                            foreach ( $editor_styles as $key => $file ) {
    1492                                    if ( $file && file_exists( "$template_dir/$file" ) ) {
    1493                                            $stylesheets[] = "$template_uri/$file";
    1494                                    }
    1495                            }
    1496                    }
    

    (from: wp-includes/theme.php, via link in AllysonSouza's comment. I imagine you should be able to get the template directory name using some of those php commands or pulling the variable, which is almost always the theme name.

    $template_dir or get_template_directory();

    Also, the following could probably be used:

    128 /**
    129  * Whether a child theme is in use.
    130  *
    131  * @since 3.0.0
    132  *
    133  * @return bool true if a child theme is in use, false otherwise.
    134  **/
    135 function is_child_theme() {
    136         return ( **TEMPLATEPATH** !== STYLESHEETPATH );
    137 }
    

    The pertinent variable(?) being TEMPLATEPATH I imagine.