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?
- LIKE vs CONTAINS on SQL Server
- What’s the best way to search for a UPC code in a Database?
- How to measure elapsed time in Python?
- What do Clustered and Non-Clustered index actually mean?
- what does O(N) mean [duplicate]
- When should I use CROSS APPLY over INNER JOIN?
- Convert Set to List without creating new List
- Fastest way to check if a value exists in a list
- Returning an empty string : efficient way in c++
- Measure the time it takes to execute a t-sql query
- How can you profile a Python script?
- Replace values in list using Python
- Most efficient way to map function over numpy array
- What’s the best way to convert a number to a string in JavaScript?
- Which Python memory profiler is recommended? [closed]
- What is the difference between spark.sql.shuffle.partitions and spark.default.parallelism?
- Python Sets vs Lists
- Big O, how do you calculate/approximate it?
- What is the difference between call and apply?
- What is the difference between set and hashset in C++ STL?
- Returning an empty string : efficient way in c++
- Declaring multiple variables in JavaScript
- Count(*) vs Count(1) – SQL Server
- HashSet vs. List performance
- Static linking vs dynamic linking
- How to get current time in milliseconds?
- Best way to reverse a string
- Is Python faster and lighter than C++?
- When should we use Radix sort?
- ADB stopping at (waiting for devices)
- Fastest way to remove first char in a String
- Make first letter of a string upper case (with maximum performance)
- Best way to test if a row exists in a MySQL table
- Efficient way to do batch INSERTS with JDBC
- Java check if boolean is null
- What is the best way to profile javascript execution?
- Is it more efficient to return a const reference
- the asymptotic growth of n choose floor(n/2)
- Fastest way to generate a random boolean
- what is ScriptResource.axd in the page load in web app?
- How to parallelize downloads across hostnames on WordPress?
- How to parallelize downloads across hostnames on WordPress?
- Get difference between two lists
- How to create a new object instance from a Type
- MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET
- C++ performance vs. Java/C#
- How to use Memcached with PHP7?
- What’s the best way to dedupe a table?
- Steps to optimize WordPress in regard to server load and website speed?
- Do deactivated plugins slow down a WordPress site?
- Ajax takes 10x as long as it should/could
- How well does WordPress scale?
- What are the best practices for using a caching plugin on a shared host?
- Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?
- get_option() vs get_theme_mod(): Why is one slower?
- Slow Query for the wp_options table
- Delete all posts of a custom post type—efficiently
- Are WordPress Heartbeat API ‘beats’ staggered or do they occur simultaneously for all users?
- Performance of my permalink structure?
- What is the best caching option for WordPress multi-site on non-shared hosting?
- WordPress usermeta scaling for thousands of users
- How can I debug the TTFB in WP?
- 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?
- Why is home (a lot) slower than other pages?
- How to share WordPress core library
- How to use Head JS with all enqueued scripts?
- WordPress SLOW, tried everything!
- Strategies to implement selective loading of plugins