Hello, welcome to therichpost.com. In this post, I will tell you, How to add Enqueue Script and Style for Single page, Archive Page and Page Templates? WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.
In this post, we will add conditional scripts or styles for particular page template,
custom post type single pages or archive pages and this is very useful.
Here is the working wordpress hook for How to add Enqueue Script and Style for Single page, Archive Page and Page Templates, and you need to add this into your theme’s functions.php file:
add_action( 'wp_enqueue_scripts', 'so_50916971_enqueue_scripts' ); function so_50916971_enqueue_scripts(){ /**For single of archive page */ if( is_singular( 'movies' ) || is_post_type_archive( 'movies' ) ){ wp_enqueue_style( 'my-movie-style', /* src to .css file */ ); wp_enqueue_script( 'my-movie-script', /* src to .js file */ ); } /** For page templates */ if ( is_page( 'landing-page-template-one' ) ) { //you style } }
Now you are done and if you have query related to this post or you want to do some more with this code then please do comment below and I will come with wordpress hooks.
Recent Comments