• Resolved IT Hertz

    (@it-hertz)


    I use a number of plugins and I’m getting fed up with them forcing styles via a multitude of !important properties, spread across numerous files that override my child styles.

    My child style.css is loading before the offending stylesheets, so using my own !importants is pointless.

    I read somewhere that !important in the page head has priority over all stylesheets, but I’m not keen on doing that. I want to keep everything in style.css.

    For now I must dequeue each offending file, copy its contents into a new stylesheet file in my child theme and enqueue that. Sure, it works, but I keep running into new files that override my work. Also, the likelihood that a theme or plugin dev will make changes in an update that will break my styles is increased doing it this way. Devs putting that !important crap everywhere is so aggravating.

    I could find no solutions to this via much Googling. I tried some array schemes and enqueue loops; no joy. I looked through the WP enqueue docs as well. Registering and deregistering are not helping, and obviously I only want to modify certain css, not mass remove the originals. I’m sure this must be easy, and I must be doing something stupid simple wrong, but I’m stumped.

    Does anyone have a functions snippet that actually forces the child style.css to load LAST, after parent, after plugins, after everything?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @it-hertz

    You can use get_footer filter to load your child style in footer as given in below.

    function prefix_add_footer_styles() {
        wp_enqueue_style('mystyle', get_template_directory_uri() . '/css/mystyle.css', array(), '1.0.0', 'all');
    };
    add_action( 'get_footer', 'prefix_add_footer_styles' );

    As you said important parameter not working on your style please also check recent updated effecting in site easily or not. Might be you have caching enabled that always load old css and not new.

    Hope this will help you!

    Thread Starter IT Hertz

    (@it-hertz)

    Perfect! Thank you!

    Thread Starter IT Hertz

    (@it-hertz)

    Hello,

    I now have need to modify the back end appearance, and none of the admin editor plugins do what I need.

    Unfortunately, the above trick doesn’t work for these pages (e.g. users.php), since there is no <footer> tag as with front end pages, which apparently is what get_footer requires.

    This also works on front end pages, but not back end:

    add_action('wp_enqueue_scripts', 'enqueue_last', PHP_INT_MAX);
    function enqueue_last() {
       wp_enqueue_style('theme-child-style', get_template_directory_uri() . '-child/style.css', array(), '4.0', 'all');
    }

    In the page source, the child stylesheet appears after all the other ones.

    Thinking the get_template was causing a problem for the back end pages, I then tried this:

    add_action('wp_enqueue_scripts', 'enqueue_last', PHP_INT_MAX);
    function enqueue_last() {
       $dir = plugin_dir_url(__FILE__);
       wp_enqueue_style('theme-child-style', $dir . 'style.css', array(), '4.0', 'all');
    }

    No joy. I also tried it with style.css in a separate plugins/child folder; still no joy.

    I thought it might not be working because I hadn’t registered the stylesheet, so I next tried that before enqueue; still no joy.

    All of the plugin stylesheets are being enqueued normally, but I can’t get mine to. It doesn’t appear anywhere in the page source.

    What am I neglecting to do or doing wrong?

    Thread Starter IT Hertz

    (@it-hertz)

    I had forgotten about admin_enqueue_scripts action and was recently reminded in another thread. Problem solved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘enqueue child style LAST?’ is closed to new replies.