最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trying to get my CSS files to load last using add_action(after_setup_theme, add_css_js, 100000)

programmeradmin1浏览0评论

I am trying to get my CSS files to load after the theme and plugins have been loaded using add_action(after_setup_theme, add_css_js, 100000)

function add_css_js(){
    wp_enqueue_style(
        'color',
        trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/color.css' 
    );
    wp_enqueue_style(
        'gem',
        trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/gem.css'
    );
}
add_action( 'after_setup_theme', 'add_css_js', 100000);

I am trying to get my CSS files to load after the theme and plugins have been loaded using add_action(after_setup_theme, add_css_js, 100000)

function add_css_js(){
    wp_enqueue_style(
        'color',
        trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/color.css' 
    );
    wp_enqueue_style(
        'gem',
        trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/gem.css'
    );
}
add_action( 'after_setup_theme', 'add_css_js', 100000);
Share Improve this question edited Jun 8, 2020 at 21:28 Pat J 12.4k2 gold badges28 silver badges36 bronze badges asked Jun 6, 2020 at 21:17 McLuvinMcLuvin 1 4
  • 1 You need to show us what is in this function: add_css_js. And the add_action needs to be like this: add_action('after_setup_theme', 'add_css_js', 100000); – shanebp Commented Jun 6, 2020 at 21:34
  • 2 If you're loading CSS files, you should be using wp_enqueue_style(), which allows you to define your CSS file's dependencies. – Pat J Commented Jun 6, 2020 at 21:49
  • function add_css_js(){ wp_enqueue_style( 'color', trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/color.css' ); wp_enqueue_style( 'gem', trailingslashit( get_theme_root_uri() ) . 'gemtechllc/css/gem.css' ); } add_action( 'after_setup_theme', 'add_css_js', 100000); – McLuvin Commented Jun 7, 2020 at 0:19
  • For future reference, it's preferable to edit your question to add context, rather than providing it in comments (especially if you're adding code samples, since they're very difficult to read with no formatting applied). – Pat J Commented Jun 8, 2020 at 21:26
Add a comment  | 

1 Answer 1

Reset to default 0

Sorry I am unable to comment so I have to post here.

I will give this answer as some examples and then hopefully you can use in your situation or provide further information about your exact setup.

Make sure you are using a child theme (If you are unsure about what this is please read this

In my sites I find I am using storefront a lot so an easy way to start off with child themes would be to give this one a try

Ok so now that we are on the same page in your Child theme functions.php add or un comment the following:

/**
 * Dequeue the Storefront Parent theme core CSS
 */
function sf_child_theme_dequeue_style() {
    wp_dequeue_style( 'storefront-style' );
    wp_dequeue_style( 'storefront-woocommerce-style' );
}

Once you have that done you can add any css to your stylesheet (style.css) or even add css from within your function pages.

I really hope this helps!

If not please provide details of the theme and the function you are trying to use / call.

Cheers,

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论