Categories

Thursday, December 26, 2024
#919814419350 therichposts@gmail.com
Wordpress Hooks

How to add Enqueue Script and Style for Single page, Archive Page and Page Templates?

How to add custom meta title and meta description in Wordpress?

Enqueue Script and Style for Single page, Archive Page and Page Templates

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.

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.