Not working on home page
-
First, thanks for a great plugin!
I just installed it and it’s working great on all my pages and blog posts. However, it doesn’t seem to be doing anything on my home page. In Settings->Reading Settings, I have “Front page displays” set to “Your latest posts.”
I’ve made sure to purge caches as well.
Any ideas?
Thanks!
– Andrew
-
Andrew,
Thanks for posting. It’s hard to say without looking at the theme php files, but likely there is a non-standard method to enqueue your scripts. Are you sure you haven’t turned the plugin off for that page (there is a metabox for pages to turn off Scripts-to-Footer, if you can’t see it on the Page edit screen, check your screen options in the upper right).
I see the same result on every page, so it looks like it’s being consistent and not limited to just the front page (which, in this case, is your theme’s blog template, based on your settings).
I can’t change other plugins or theme files, unfortunately. I’d offer my services, but I’m completely booked at the moment. Best option is to figure out which scripts are not being moved, where they come from (a plugin or a theme) and then identify if that plugin/theme is correctly using
wp_enqueue_scripts
for their script placement.Hope that helps,
JoshuaThanks for the super-quick reply, Joshua!
Since I have “Front Page Displays” set to “your latest posts,” my site doesn’t have a separate page that’s used for the homepage — so I don’t have the metabox option for disabling the plugin.
What’s weird is that there’s a big batch of scripts that show up in the <head> on the homepage, but they do correctly move to the bottom of the page on posts/pages.
<script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-includes/js/jquery/jquery.js?ver=1.11.2'></script> <script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script> <script type='text/javascript' src='https://eatingrules.com/wp-includes/js/jquery/ui/core.min.js?ver=1.11.4'></script> <script type='text/javascript' src='https://eatingrules.com/wp-includes/js/jquery/ui/widget.min.js?ver=1.11.4'></script> <script type='text/javascript' src='https://eatingrules.com/wp-includes/js/jquery/ui/button.min.js?ver=1.11.4'></script> <script type='text/javascript' src='https://eatingrules.com/wp-content/plugins/easyrecipeplus/js/easyrecipe-min.js?ver=3.3.3077'></script> <script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-content/themes/canvas/includes/js/third-party.min.js?ver=4.2.2'></script> <script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-content/themes/canvas/includes/js/modernizr.min.js?ver=2.6.2'></script> <script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-content/themes/canvas/includes/js/general.min.js?ver=4.2.2'></script>
There shouldn’t be anything different about the home page, as far as I can tell… and since it works fine for all other pages, I think the theme is probably enqueuing scripts correctly.
For what it’s worth, I’m using WooThemes Canvas, with my own child theme.
Not a huge deal — my site is already much better off than it was a couple of hours ago!
Thanks again,
AndrewOne additional bit of info that might be helpful. It seems to be having the issue for the date-based archives pages as well. So if I view https://eatingrules.com/2014/ to show all the posts from 2014 (for example), it’s not moving those scripts either.
I poked around in the theme files, but didn’t find anything that would seem to be causing the issue.
Here’s the relevant (I think) bit of the /includes/theme-js.php file (called by the main functions.php).
if ( ! function_exists( 'woothemes_add_javascript' ) ) { function woothemes_add_javascript() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script( 'third-party', get_template_directory_uri() . '/includes/js/third-party' . $suffix . '.js', array( 'jquery' ) ); wp_register_script( 'flexslider', get_template_directory_uri() . '/includes/js/jquery.flexslider' . $suffix . '.js', array( 'jquery' ) ); wp_register_script( 'prettyPhoto', get_template_directory_uri() . '/includes/js/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ) ); wp_register_script( 'portfolio', get_template_directory_uri() . '/includes/js/portfolio' . $suffix . '.js', array( 'jquery', 'prettyPhoto' ) ); wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/includes/js/modernizr' . $suffix . '.js', array( 'jquery' ), '2.6.2' ); // Conditionally load the Slider and Portfolio JavaScript, where needed. $load_slider_js = false; $load_portfolio_js = false; if ( ( get_option( 'woo_slider_magazine' ) == 'true' && is_page_template( 'template-magazine.php' ) ) || ( get_option( 'woo_slider_biz' ) == 'true' && is_page_template( 'template-biz.php' ) ) || is_page_template( 'template-widgets.php' ) || ( is_active_sidebar( 'homepage' ) && ( is_home() || is_front_page() ) ) ) { $load_slider_js = true; } if ( is_page_template( 'template-portfolio.php' ) || ( is_singular() && ( get_post_type() == 'portfolio' ) ) || is_post_type_archive( 'portfolio' ) || is_tax( 'portfolio-gallery' ) ) { $load_portfolio_js = true; } // Allow child themes/plugins to load the slider and portfolio JavaScript when they need it. $load_slider_js = apply_filters( 'woo_load_slider_js', $load_slider_js ); $load_portfolio_js = apply_filters( 'woo_load_portfolio_js', $load_portfolio_js ); if ( $load_slider_js ) { wp_enqueue_script( 'flexslider' ); } if ( $load_portfolio_js ) { wp_enqueue_script( 'portfolio' ); } do_action( 'woothemes_add_javascript' ); wp_enqueue_script( 'general', get_template_directory_uri() . '/includes/js/general' . $suffix . '.js', array( 'jquery', 'third-party' ) ); } // End woothemes_add_javascript() }
Andrew,
Thanks for the follow up. Again, I’m not seeing any difference between your home page, date archive, single post/page. They all look the same in terms of the location of the scripts.
Almost forgot, but this could be a simple fix if it’s the issue: Do you have a caching plugin running? Perhaps you need to clear the cache.
I’m not sure how that WooTheme enqueues the scripts, but likely they do it correctly and hook in the
woothemes_add_javascript
function correctly, those guys are good developers.Are you using the most current version of the plugin?
It could also be a plugin conflict. At this point, if you’d like to keep going forward with troubleshooting, I’d recommend deactivating every plugin and reverting to a standard theme, then turn on Scripts-to-Footer and confirm that it’s working (which you may not have any scripts with a base theme and no plugins, so you might have to turn on another plugin).
If it’s working at this point, turn on each plugin one at a time and check each time to see if one changes the behavior. If not, then try your theme and see. This will let you narrow-in on the issue and help us determine if it’s a conflict with another plugin or your theme.
Honestly, though, unless you have some custom code changing the behavior of Scripts-to-Footer specifically, a very custom/unique WordPress setup, or you’re plugin/theme is not using the hook method linked above, it should work. It’s a very basic plugin that only removes a few built-in hooks.
Hope that helps!
JoshuaHey Joshua,
I appreciate your continuing to help on this, especially since you’re so busy!
My WordPress and all Plugins are up-to-date (I actually just installed your plugin yesterday for the first time).
I did clear the W3 Total Cache page cache multiple times, and confirmed I’m seeing fresh copies of the homepage source and other pages (it puts a timestamp at the very end of the html doc)… and yet I’m still seeing javascripts in the <head> on the homepage but not on blog posts pages. I’m also viewing it logged-out, so I should be seeing the exact same pages you are.
For example, on my homepage, jquery (among others) is called in the <head> section:
<script type='text/javascript' src='https://djuf8khon03er.cloudfront.net/wp-includes/js/jquery/jquery.js?ver=1.11.2'></script>
But on my most recent blog post, jquery (and all other enqueued javascript files) is loaded at the bottom of the page.
So I’m scratching my own <head> trying to figure out why it’s showing up differently for you!
Andrew,
I see it the same as you now. Perhaps I was looking at the wrong page earlier or viewed it during a period you had it off, who knows! ??
I’m at a loss as to why it wouldn’t be working on the home page. It’s possible that your theme has a separate home page/blog template that queues the scripts differently?
You could create such a template, then write a function to manually remove the scripts from the header and place them in the footer just for that condition. Or, use your
functions.php
and build a function with some conditionals to do the same.Unfortunately, there’s not really an easy way for me to replicate this issue and so far as I can see this is a unique issue related to your site. I might have some time in later July if you’d like to hire me to look at it.
Sorry I can’t be of more help, but let me know if I can answer any other questions!
Cheers,
JoshuaJoshua — thanks for the very helpful plugin. I actually had the same problem — this plugin doesn’t do anything on the home page — and I looked into the plugin code and found the problem pretty quickly.
You are conditioning running everything on get_queried_object_id() returning a non-0 value. Trouble is, in my theme (as in many), the home page isn’t a ‘page’, and it doesn’t have a post_id or page_id.
For my own hack I made changed these two lines in your main plugin file
if( get_queried_object_id() ) { $queried_object_id = get_queried_object_id();
to
if( get_queried_object_id() ) { $queried_object_id = get_queried_object_id(); } elseif (is_home()){ $queried_object_id = 1; } if ($queried_object_id){
This is imperfect fix — I don’t use date-based archives and I suspect we’d have the same problem on them — but it worked for my case like a charm.
wmgtam,
Thanks for the feedback and catching this issue! I’ll do some testing on this later tonight and try to get an update pushed through in the next couple of days. I’d like to make sure it’s working on any page that would have this result (I think date-based archives work, but not correctly, by returning the first post’s id).
Anyway, greatly appreciate the catch and I’ll work on an update.
Cheers,
JoshuaHey guys,
I’ve got a somewhat stable version in development that should resolve this issue, if you have a chance to take a look and test it (not on a production site), I’d appreciate any feedback! I’m hoping to have this update ready in the next week or so.
Thanks,
JoshuaI’ve released this new version that includes an option to keep jquery in the header (Settings > Scripts to Footer), as well as options for archives – you can now exclude the plugin from specific archive types (category, author, blog, etc). If you need further help, please open a new issue. I’m closing this one.
- The topic ‘Not working on home page’ is closed to new replies.