Home>Support>functions.php vantage_scripts question

functions.php vantage_scripts question

By jjfoerch, 7 years ago. Last reply by jjfoerch, 7 years ago.

Hello,

I’m developing a child theme of vantage, and ran across what seems like an odd behavior in how WordPress child themes work. In functions.php, vantage_scripts enqueues Vantages’s styles.css with this call:

wp_enqueue_style( 'vantage-style', get_stylesheet_uri(), array(), SITEORIGIN_THEME_VERSION );

However, when there is a child theme, this actually resolves to style.css in the child theme instead of in Vantage. In order for Vantage’s css to be correctly included in this case, the child theme must override the ‘vantage-style’ inclusion by doing this:

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

This strikes me as being both fragile and breaking modularity, that the child theme would need to know inner details of the parent theme. It would be simpler if each theme were only responsible for its own stylesheets, i.e., Vantage would use get_template_directory_uri() instead of get_stylesheet_uri() to build the uri of its style.css.

Is this a change that would make sense for Vantage to adopt, or are there other cases to consider where the current way is superior?

Thank you,

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 7 years, 7 months ago Alex S
    Hi, I Work Here

    Hi Jjfoerch,

    Unfortunately, this isn’t something we can ever regardless of what method is superior. Too many child themes rely on the current method so releasing an update that changes things could cause major issues for major issues for certain user. We recommend adding the following PHP to your child theme:

    function vantage_child_enqueue_parent_style() {
        wp_enqueue_style( 'vantage-parent-style', get_template_directory_uri() . '/style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'vantage_child_enqueue_parent_style', 8 );
    
    

    Regardless of this, there is an advantage to how we’re doing things. Basically, it allows the designer to completely remove the default stylesheet out of the mix and thus not have to fight with it if they so desire.

  2. 7 years, 7 months ago jjfoerch

    Hi Alex,

    Ah, I see. Thank you so much for the explanation.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More