• Resolved Rapforthemoment

    (@rapforthemoment)


    Just tried making a new child theme for the HappenStance theme. Please tell me if it looks right. It seems to be functioning properly, but I don’t want to take any chances of it breaking down or updating and all my work being erased.

    /*
    Theme Name: HappenStance Child Theme
    Theme URI: https://rapforthemoment.com/happenstance-child-theme/
    Description: HappenStance Child Theme
    Author: Jeff Arnold
    Author URI: https://rapforthemoment.com
    Template: happenstance
    Version: 1.0.0
    License: GNU General Public License v2 or later
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
    Text Domain: happenstance-child-theme
    */

    @import url(‘../happenstance/style.css’);

    ———————————————–

    I also made an functions.php file with this code:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_styles’ );
    function enqueue_parent_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }

    ———————————————–

    Does everything seem to be in order? My website is rapforthemoment.com. Child Theme is currently running. At least what I think is my perfected child theme.

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

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You don’t need to use both the @import line and enqueue function, use either.

    If something was wrong then it would be noticeable, for example you wouldn’t be able to activate your Child Theme in the dashboard, or your website would contain no styling.

    The correct method for adding a stylesheet is to use wp_enqueue_style and not import. Currently you are using both methods.

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    If I do not use the @import then the styles of the parent theme vanish. It’s like I’m basically just left with text and images.

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    I just took out the @import and look what it does to my site: https://www.rapforthemoment.com

    I don’t know if it’s supposed to be like that with the wp_enqueue code but I want the styles.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    So I would paste this code:

    require_once( get_stylesheet_directory() . ‘/my_included_file.php’ );

    inside of my php file?

    What happens if I just use the @import, or both? Seems to work fine with both.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oh no sorry, I meant instead of this line of code you have:

    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

    Use this:

    wp_enqueue_style( 'parent-style',  get_stylesheet_directory().'/style.css' );

    What happens if I just use the @import, or both? Seems to work fine with both.

    But it’s not using both. Your enqueue function not working, but your @import line is working.

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    Alright I replaced the code to this:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_styles’ );
    function enqueue_parent_styles() {
    wp_enqueue_style( ‘parent-style’, get_stylesheet_directory().’/style.css’ );
    }

    It still shows no sign of styling. It the Wp_enq now working or..?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oh no sorry you probably don’t need that at all, please undo that by replacing this:

    wp_enqueue_style( 'parent-style',  get_stylesheet_directory().'/style.css' );

    With this:

    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    Switched it out and it still has no styling. Hmm. What could it be?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I think for some reason your functions.php file isn’t being read, can you try outputting something just to make sure it’s at least being read? E.g. underneath this line:

    <?php

    Add this:

    echo('foo');

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    <?php
    echo(‘foo’);

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_styles’ );
    function enqueue_parent_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }

    Added it in.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Does it output ‘foo’ anywhere on your page?

    Thread Starter Rapforthemoment

    (@rapforthemoment)

    Not that I can find, nowhere. Huh. Should this mean I should just use the import? I’d hate to lose the benefits of using the wp_enq but if it works.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Hmm maybe, can you triple check the name of your functions.php file? It’s definitely not “function.php”, right?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘The correct format for a Child Theme?’ is closed to new replies.