- This topic has 15 replies, 5 voices, and was last updated 3 years, 11 months ago by
Leo.
-
AuthorPosts
-
January 11, 2016 at 3:34 pm #165156
Hftt
Hi Tom
Is there way to load child theme css before parent stylesheet?
I’d love to see my child css without !important patches. Please help me.
Always THANKS!
Paris
-
This topic was modified 7 years, 10 months ago by
Tom.
January 11, 2016 at 3:35 pm #165157Tom
Lead DeveloperLead DeveloperPlacing your child theme CSS before the parent CSS will require you to use !important.
Loading your child CSS after the parent CSS makes your child CSS more important, so you don’t need to use !important or be more specific.
January 11, 2016 at 4:02 pm #165168Hftt
Arr … my bad. Wrong question. SORRY.
I’d like to ask you to load child theme css before plugin stylesheets. If possible, I can override WooCommerce styles in child theme without using !important.
Long ago, when I was Genesis devotee (not anymore after using GP π ) – there was a plugin – let me search – oh it still exists – “Genesis Style Trump” – https://wordpress.org/plugins/genesis-style-trump/.
If I can do that in GeneratePress, that will be awesome!
January 11, 2016 at 11:25 pm #165194Tom
Lead DeveloperLead DeveloperAh, I gotcha π
You should be able to do it like this:
add_action( 'wp_enqueue_scripts', 'generate_remove_scripts' ); function generate_remove_scripts() { wp_dequeue_style( 'generate-child' ); } add_action( 'wp_enqueue_scripts', 'generate_move_scripts', 999 ); function generate_move_scripts() { if ( is_child_theme() ) : wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' ); endif; }
Let me know π
January 12, 2016 at 8:53 am #165329Hftt
That’s brilliant move. It works!
Thank you very much Tom. You are amazing.
January 12, 2016 at 9:56 am #165345Tom
Lead DeveloperLead DeveloperYou’re very welcome π
April 1, 2016 at 12:51 pm #183512Jessica
Would there be a way to do this with GP hooks? I am attempting to avoid creating a child theme.
For us, we are using a custom CSS plugin which works great, except that there’s just 1 for the whole site. I’d like to set up a homepage .css file that I can call with a hook so that it doesn’t load on all pages. Is this possible?
April 1, 2016 at 5:17 pm #183546Tom
Lead DeveloperLead DeveloperYou could do something like this in the wp_head hook:
<?php if ( is_front_page() ) : ?> <link rel='stylesheet' href='URL TO YOUR CUSTOM STYLESHEET' type='text/css' media='all' /> <?php endif; ?>
That will load it only on the home page π
April 4, 2016 at 7:27 am #184042Jessica
Hi Tom,
Thank you for the suggestion. The CUSTOM.css style sheet did appear in the header as needed, but it appears that it is de-prioritized. The CUSTOM.css is being overwritten by site-wide style sheets. Is there a way to add a function, for only the home page, that prioritizes CUSTOM.css?
Thank you!
JessicaApril 4, 2016 at 9:58 am #184107Tom
Lead DeveloperLead DeveloperAbsolutely!
add_action( 'wp_enqueue_scripts', 'my_custom_scripts', 500 ); function my_custom_scripts() { // Bail if we're not on the front page if ( ! is_front_page() ) return; wp_enqueue_style( 'my-custom-style', 'URL TO YOUR STYLESHEET', false, '1.0', 'all' ); }
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
Let me know if you need more info π
-
This reply was modified 7 years, 8 months ago by
Tom.
April 4, 2016 at 10:00 am #184110Jessica
Excellent, thanks so much!
April 4, 2016 at 10:02 am #184115Tom
Lead DeveloperLead DeveloperYou’re welcome π
April 4, 2016 at 10:28 am #184127Jessica
This worked beautifully! Thanks again!
A quick note: the redirect for editing custom PHP in the Generate Simple PHP plugin did not take me to the correct place to edit within the WP interface (it took me to Plugin editing, but to the first alpha plugin not to Generate Custom PHP).
I ended up just editing custom.php within Notepad++ FTP and that worked great, but I wanted to let you know about the redirect. We are running multisite, so that may have caused the issue.
April 4, 2016 at 11:11 am #184138Tom
Lead DeveloperLead DeveloperThat’s very weird – I just checked and it’s working on a regular install, so it must be a multi site issue.
I’ll see if I can figure it out π
January 7, 2020 at 3:59 pm #1125148Gabriela
Hi!
I am working with a child theme from Generatepress, and with Woocommerce plugin.Some styles from child are ineffective in Woocommerce pages.
Is there a function so that I load my child-theme style last of all?
-
This topic was modified 7 years, 10 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.