• Can someone point me to a good reference on child themes? I’ve created a child theme (with the appropriate style and index.phpfile). And it works, at least modifying the style sheet.

    But when I try to override some files in the parent theme (Klasik Framework). My child files are ignored.

    For example, I’m trying to override klasik > includes >widgets > klasik-latestnews-widget.php

    So I created the same directory page in my child: mychild > includes > widgets > klasik-latestnews-widget.php

    Changes to the child theme file are ignored. If I change the same file in the parent theme, it works.

    What’s happening?

    Thanks,

    John

Viewing 10 replies - 1 through 10 (of 10 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    These questions are theme-specific. Do you mean this theme: https://wordpress.org/themes/klasik/ ?

    Try creating a blank page called functions.php for the child theme. That worked for me with a similar problem.

    I have another site where I had to copy the actual functions.php over to the child theme.

    And another one where I had to make a functions.php with this code in it to call the jquery…

    <?php
    
    function mh_load_my_script() {
        wp_enqueue_script( 'jquery' );
    }
    
    add_action( 'wp_enqueue_scripts', 'mh_load_my_script' );
    
    ?>

    It can’t hurt to try either of those but make sure you don’t delete or alter your original functions.php or it might break your site.

    And as always do a backup first just in case. Good luck.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It can’t hurt to try either of those but make sure you don’t delete or alter your original functions.php or it might break your site.

    I’d say it can. Copying the functions.php file over into your Child Theme will most likely break your site.

    it will most likely break it yes and if it breaks the site then go back in and delete it. It would only be but a minutes time worth of effort. But it has worked for me once.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    This is why general advice for editing theme-specific functions is not good.

    If a function in the parent theme is pluggable, it allows you to copy a function from the parent theme into the child theme’s functions.php and have it replace the one in your parent theme. The only requirement is that the parent theme’s function is pluggable, which basically means it is wrapped in a conditional if statement e.g:

    if (!function_exists("parent_function_name")) {
         parent_function_name() {
              ...
         }
    }

    If the parent theme function is pluggable, you can copy it to the child theme functions.php and modify the function to your liking.

    Thread Starter jgold723

    (@jgold723)

    Hmmm,but this isn’t a function (well, at least I don’t think it’s a function). It’s a template file and I’m simply trying to change a tiny bit of the html. I’m discovering that the whole WordPress child theme theory works fine, as long as the files you are changing all reside in the root directory of the parent theme. If the parent theme has files that are in subdirectories (i.e. /includes/widgets/file.php) an identical file in the child theme will be ignored.

    I’d ask the developer of the parent theme (Klasik) but they are worthless — have provided no support at all.

    you could try setting an absolute path.

    IF BEFORE

    <link rel="stylesheet" type="text/css" href="style.css" />

    NOW:

    <link rel="stylesheet" type="text/css" href="http://host/path/to/style.css" />

    replace host/path/to with the correct location for your child theme css file.

    then add an include statement in child theme index.php

    such as

    <?php
    include ("html/yourfilenamehere.html");
    ?>
    
    <?php
    include ("php/klasik-latestnews-widget.php");
    ?>

    all of this is done in the child theme.

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    If you want a child theme’s files to override the parent, the thing to remember is that the parent theme has to use the proper functions when loading files.

    The ones that cannot be overridden are basic PHP functions like include|require and (include|require)_once. Often times a parent theme will want a user to override an image/style so they use get_stylesheet_* functions in order to do so in conjunction.

    Let’s take for example 2015:

    if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) {
    	require get_template_directory() . '/inc/back-compat.php';

    The file back-compat.php will not be overridden by a child theme because it will use the template_directory rather than the stylesheet_directory to load the file.

    If I wanted a user to use their own image for a default post thumbnail I could use something like:

    if ( ! has_post_thumbnail() ){
    	echo get_stylesheet_diretory_uri() . '/img/default-thumb.jpg';
    }

    There are a lot of ways to making a parent theme very child theme friendly you just have to know what functions/template tags to use.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Help with Child Theme 101’ is closed to new replies.