• I’ve read a lot of good help on this, but, with new, and limited, wp and js skills, I want to make sure of my understanding.

    To allow the parent theme (‘hashi’) to evolve, I’m using a child theme (‘hashi-child’) to capture unique (e.g. ‘special’) and override element (e.g. ‘h1’) styles. The directory and styles.css files have been created. My understanding is that to create the enqueue cascade I need a functions.php file with some js, and, when created, activate the hashi-child theme to implement.

    The codex for enqueue has recommended js to do this (below). Is the ” $parent_style = ‘hashi’ ” the only change I need or do I also need to change the name for the child in the second wp_enqueue statement?

    <?php
    function my_theme_enqueue_styles() {

    $parent_style = ‘parent-style’; // This is ‘twentyfifteen-style’ for the Twenty Fifteen theme.

    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 ),
    wp_get_theme()->get(‘Version’)
    );
    }
    add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @tdcarp,
    In order to create a child theme, you basically need to add the following line in the style.css of your child theme folder where you have defined the name of your child theme, like

    /*
    Theme Name: Hashi Child Theme
    Theme URI: YOUR THEME URL
    Description: DESCRIPTION OF YOUR THEME
    Author: THEME AUTHOR
    Author URI: AUTHOR URI (IF ANY)
    License: GNU General Public License v3 or later
    License URI: http://www.gnu.org/licenses/gpl-3.0.html
    Template: hashi
    Version: 1.0.0
    */

    You need to take care of the line – Template: hashi
    this will inform wordpress that the theme is a child theme whose parent is “hashi”

    And you have already enqueued the styles of the parent in the child, that is all fine.

    Thanks!

    Thread Starter tdcarp

    (@tdcarp)

    Wow! Very easy! I’ll test it right away. With this approach, do I still activate the child theme?

    Is the theme uri also important, or just the template statement?

    Now I’m confused by the enqueue codex. In non-wp sites, I’d add a style link to the Head of pages to enqueue style files. Apparently, the use of @style is no longer recommended and this js code is needed to create the effect of style links.

    Also confused because the codex recommends this for the child style:

    /*

    Theme Name: Hashi-child
    Description: Greater Maple Valley Unincorporated Area Coucil (GMVUAC) style sheet
    Version: 1.0.0
    Author: Tom Carpenter
    License: GNU General Public License v2 or any later version
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Tags: gmvuac
    Copyright 2016 Tom Caroenter
    All of the theme’s PHP and CSS files are licensed under the GNU General Public License, version 2 or any later version:

    http://www.gnu.org/licenses/gpl-2.0.html

    Other files are licensed as follows:

    * hbg.jpg is released into the public domain;

    * bbg.png, black_list_bullet.png, blue_list_bullet.png, close_menu.png, open_menu.png, sbg.png, wbg-smaller.png and wbg.png are ineligible for copyright because they are trivial.

    */

    • This reply was modified 9 years, 8 months ago by tdcarp.

    Hi @tdcarp,
    Yes, you need to activate the child theme only, as any modification that will be done, will be done within the child theme.

    No, the Theme URI statement is not the mandatory part, but the Template is necessary.
    Dont get confuse by any code on codex for the child style code. The lines of code:

    /*
    Theme Name: Hashi Child Theme
    Theme URI: YOUR THEME URL
    Description: DESCRIPTION OF YOUR THEME
    Author: THEME AUTHOR
    Author URI: AUTHOR URI (IF ANY)
    License: GNU General Public License v3 or later
    License URI: http://www.gnu.org/licenses/gpl-3.0.html
    Template: hashi
    Version: 1.0.0
    */

    will work perfectly for you.

    The enqueue statements of the parent theme’s style and js is to maintain the look and feel of the site as it is in the parent theme. But, if you wish to have a different style, you need not to add the code for enqueuing the parent style and js, you can simply add your codes in the child css and js.

    Thanks!

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

The topic ‘Need help with child enqueue code’ is closed to new replies.