method two won’t work because no page is loaded yet and $post isn’t set when your if check runs.
with method one again $post is not yet set at that point, but this method will work if you use WordPress conditionals:
function load_slider(){
if( is_page(11746) ){ // Load slider on home page
wp_register_script('start-slidorion', get_bloginfo('stylesheet_directory') . '/js/slidorion/start.js', array('slidorion', 'jquery','easing') );
wp_enqueue_script('start-slidorion' );
}
}
add_action('wp_enqueue_scripts', 'load_slider');
EDIT another example using has_term
:
function load_slider(){
global $post;
if( has_term( 'your category', 'category', $post ) ):
// enqueue your script
endif;
}
add_action('wp_enqueue_scripts', 'load_slider');
Related Posts:
- Profiling a WordPress Website for Deployment on Shared Hosting?
- What is the expected limit for acceptable performance of WordPress without any adjustments?
- Large Number of WordPress Posts
- Why does my site flash white every time it changes page? [closed]
- Restricting a Plugin to Only Load its CSS and JS on Selected Pages?
- Many POST requests to /xmlrpc.php from GoogleBot taking down server?
- How to implement a ‘fail whale’ to graciously limit server load (Solutions for system capacity governing)
- Stress testing WordPress
- What are best practices for configuring a server for WordPress sites?
- Too many MySQL connections on WordPress
- Too many posts cause slow load when paginating
- Mysql / WordPress killing my server with 80k users [closed]
- How can I measure the performance of any WordPress Plugin or Theme?
- Load testing for WordPress functionality
- WordPress takes too long to show 404 error on images (on LEMP stack)
- What’s the best way to implement AJAX in WordPress?
- Getting two versions of CSS
- High traffic management in WP
- Server technical information and first respond time for WordPress
- Load-Testing a WordPress Site
- Offloading cron jobs
- Is it possible to outsource wp-admin to another server?
- Internal Server Error and bad CSS
- Does having multiple random posts add up to server load and page load times?
- WordPress article with 50 000 words loading slow – 100% cpu
- Site load time increased
- WordPress very high load when click “Publish”
- how to restore a wordpress website, when hosting has got expired but the hosting company gives you a bunches of zip file?
- Could a very long article slow down all website and wpadmin?
- What’s the best way to dedupe a table?
- What are the best practices for using a caching plugin on a shared host?
- Are WordPress Heartbeat API ‘beats’ staggered or do they occur simultaneously for all users?
- Optimize apache for WP use
- What’s the difference between wp_insert_user() and wp_create_user()
- How to fix wordpress slow first time load (Local Server)?
- What’s the ideal way to profile WordPress memory usage?
- Any reason why wp_cache_set not to work?
- In terms of performance – Is unmanaged VPS better than a managed one – for WP sites?
- How can WordPress be made more memory efficient?
- WordPress speed slow after .5 million single image post via wp-cli
- WordPress performance issue. Can I debug it?
- WP_Query Performance Issues with meta_query
- How to see list of plugins
- Best settings for MySQL to speed up site? [closed]
- What is the best way to count and display the number of posts?
- server load. $_SERVER[‘REMOTE_ADDR’] and $_SERVER[‘HTTP_HOST’] [closed]
- WordPress site is sloooow, but admin is fast….any ideas?
- Improving WP_Query for performance when random posts are ordered
- Is post_class(); going to slow WordPress page speed
- cross-host benchmarking with wordpress
- Performance problem with first load
- Does registering multiple shortcodes impact performance?
- Correct way to perform non-cacheable DB query
- Reasonable Size Limit to options entry
- Improve performance by removing unnecessary database queries
- Including post thumbnail url in loop’s post object to reduce number of queries
- Is it possible to make WordPress PHP faster through caching or compiling it?
- W3 Total Cache: use cache for request with ignorable query string [closed]
- How to analyze wordpress plugin performance
- how to use shortinit in wordpress
- use of 10 new WP_Query : loading too slow (with url) [closed]
- Optimizing site speed by localizing paths
- Namespaced shortcode?
- How to combine multiple wp_insert_post into one in order to gain better performance
- How to optimize on-the-fly theme switching for mobile browsers?
- Last-Modified header support doesnât speed up server processing – want more
- Why does Thickbox jQuery load on my site?
- Performance testing a WordPress site locally?
- How do I serve fully cached full HTML on cloudfront
- Tabbed feeds with ajax vs. without on homepage [closed]
- Page load timer?
- Pages section (only) not loading after publishing large number of pages
- How can i find the cron jobs that run on my site and then move them to the server side?
- How do you make a site load faster when offloading is not an option?
- how to embed Pdf and Video Without effecting page speed?
- WordPress is very slow, even it’s not opening sometimes
- Regular XML-RPC timeouts
- Best way to store 1 billion+ posts?
- Optimize WP site for millions of posts
- Change loading order of blocks
- Create a custom and powerful search form
- Why WordPress takes time to make request to save post?
- Fatal error: Allowed memory size of bytes exhausted (tried to allocate 36 bytes)
- Custom Post Type vs Shortcode: Which one is more performant?
- Why is the server response time slowing my site down? [closed]
- Very Slow loading. Plugins report provided by P3 included
- Incomplete attachment page
- Post OrderBy slow performance
- How to handle high load of traffic of my server
- Automatically load WordPress page on server every XX hours
- How to preload the entire site with javascript?
- Using tag or inline style attribute?
- WordPress and TTFB (time to first byte) stats
- What’s a good tool for speed benchmarking? [closed]
- Is storing in a variable the result of a fonction a most powerful way to code an if structures in WordPress?
- High load average, low CPU usage – why?
- Degraded WordPress admin dashboard performance [closed]
- Hidden Elementor sections slow down website. How to fix this? [closed]
- Very long initial loading (20sec)
- Identifying Issues in Pagespeed Insights: Server Response Time and Long Main Thread Tasks