WordPress.org

Ready to get started?Download WordPress

Forums

Child theme not incorporating Child Style.css (7 posts)

  1. joejozwowski
    Member
    Posted 3 months ago #

    I've done MANY child themes in the past, but this one is currently stumping me.

    I took a look at the header of the style.css of the parent and this is what I got:

    /*
    Theme Name: Parent Theme
    Theme URI: http://www.theme-site.com
    Description: This is the parent theme
    Author: Theme Author
    Author URI: http://www.theme-site.com
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Version: 1.0
    @package Top10
    @since Top10 1.0
    */

    And here is MY child style.css

    /*
     Theme Name:   Top 10 Child
     Template:     top10
    */

    WordPress Codex says those are the only two lines "really" needed to link the parent and the child. I've never seen the @package or the @since tags in the header before, and I feel they may have something to do with my dilemma

  2. missybunnie
    Member
    Posted 3 months ago #

    I think you may need to add a function to include the stylesheet in the child's own functions.php. It shouldn't break anything just have your stylesheet take precedence over the parent stylesheet.

  3. joejozwowski
    Member
    Posted 3 months ago #

    fantastic... news code to learn. Is there a direction you can point me to this magic function?

  4. joejozwowski
    Member
    Posted 3 months ago #

    I've firgured out how to FINALLY incorporate the child theme's style.css, but the original css is still overwriting the child.

    I looked up my issue and I was informed that wp_deregister_style would unload the original, but it is not. Here's what my functions.php look like now:

    wp_deregister_style( ‘theme-style’ );
    
    $scripts_uri = get_stylesheet_uri();
    wp_register_style( 'whp-style', $scripts_uri, array(), '', 'all');
    wp_enqueue_style( 'whp-style' );
  5. batharoy
    Member
    Posted 3 months ago #

    You need to add the parent theme declaration in your child theme.
    @import url("../PARENTTHEME/style.css");

    More info here.

  6. joejozwowski
    Member
    Posted 3 months ago #

    @batharoy I already have that, but the parent.css is empty. The theme styles are being loaded through a wp_enqueue_style in the parent theme's theme-functions.php

  7. joejozwowski
    Member
    Posted 3 months ago #

    HUZZAH! The following code works:

    function remove_css(){
    	wp_dequeue_style( 'theme-style' );
    	wp_deregister_style( 'theme-style' );
    }
    add_action('wp_print_styles', 'remove_css', 99999);
    
    $scripts_uri = get_stylesheet_uri();
    wp_register_style( 'whp-style', $scripts_uri, array(), '', 'all');
    wp_enqueue_style( 'whp-style' );

    I just had to make sure the add_action was set to higher priority. THANK YOU BRAIN! THANK YOU!

Reply

You must log in to post.

About this Topic