- This topic has 7 replies, 3 voices, and was last updated 1 year, 7 months ago by
Tom.
-
AuthorPosts
-
May 13, 2019 at 10:45 am #898170
Simon
Hey Guys,
Just a quick one, I have a lot of styling that only applies to the home page as it runs off WP-show-post (which also only runs on the home page). So have created a separate css file for the home page.
What is the best way to load it? hook? functions? PHP Snippets?
Here are some examples of what I have so far:<?php if ( is_front_page() ) : ?> <link rel='stylesheet' href=‘/wp-content/themes/generatepress_child/home-style.css’ type='text/css' media='all' /> <?php endif; ?>
Or maybe:
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( ‘home-style’, '/wp-content/themes/generatepress_child/home-style.css', false, '1.0', 'all' ); }
May 13, 2019 at 10:55 am #898177Leo
StaffCustomer SupportHi there,
Looks like the second snippet should work. Similar to what Tom provided here:
https://generatepress.com/forums/topic/add-external-css-file/#post-887094It can be added using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 13, 2019 at 11:21 am #898189Simon
Added using php snippets as is. Worked like a charm.
Thanks Leo.
May 13, 2019 at 11:25 am #898190Leo
StaffCustomer SupportNo problem 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 18, 2019 at 4:18 am #933154Simon
Hey Guys,
Was just checking my PHP log and I am getting the below error caused by the above code I implemented:
PHP Warning: A non-numeric value encountered in /public/wp-content/themes/generatepress_child/functions.php on line 168
This is the line that resides on 168:
wp_enqueue_style( ‘home-style’, '/wp-content/themes/generatepress_child/home-style.css', false, '1.0', 'all' );
And this is the whole section:
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( ‘home-style’, '/wp-content/themes/generatepress_child/home-style.css', false, '1.0', 'all' ); }
Any thoughts on why thats triggering an error?
Cheers,
SimonJune 18, 2019 at 6:52 am #933482Tom
Lead DeveloperLead DeveloperThe only issue I’m seeing there is the curly quotes around
home-style
. I would also use the full URL to the stylesheet instead of starting with/wp-content/
.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 18, 2019 at 9:02 am #933627Simon
I think that has fixed it. Thank you Tommo.
June 18, 2019 at 3:23 pm #933938Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.