Home › Blog › How To Use wp_enqueue_script or wp_enqueue_style For Specific Page, Post or Post Type
WordPress Guides · October 30, 2018 · 3 min read

How To Use wp_enqueue_script or wp_enqueue_style For Specific Page, Post or Post Type

Mohammad Saiful Islam
WPExtent
How To Use wp_enqueue_script or wp_enqueue_style For Specific Page, Post or Post Type

It really needs sometimes to use wp_enqueue_script or wp_enqueue_style for specific page or post. If you would like to enqueue a style or script in your WordPress site then it’s the right article for you. I’ve discussed below how to enqueue a file for a specific page or post in a WordPress site. So let’s get started.

This step I’ll follow for making this post more useful for you.

How to enqueue a file for a specific page.

// use of wp_enqueue_style() for specific page
// let’s check we are in the specific page
// we can use page ID or page Slug
function webextent_enqueue_styles() {
    if ( is_page( 33 ) ) {
      wp_enqueue_style( ‘custom-stylesheet’, get_template_directory_uri() . '/style.css' );
     }
  }
add_action( 'wp_enqueue_scripts', 'webextent_enqueue_styles' );
use of wp_enqueue_script() for a specific page

// let’s check we are in the right page
// we can use page ID or Slug to check
function webextent_name_scripts() {
 if ( is_page( 34 ) {
     wp_enqueue_script( 'webextent-custom-script', get_template_directory_uri() . '/js/webextent-custom.js', array(), '1.0.0', true );
  }
}
add_action( 'wp_enqueue_scripts', 'webextent_name_scripts' );

If you don’t know how to collect a post ID, you visit how to add body class in a WordPress site where I’ve shown how to collect post ID or page ID.

Now I would like to discuss how to enqueue file for specific post

How to enqueue a file for a specific post

// let’s check we are in the specific post
// we can use page ID or post title
function webextent_enqueue_styles() {
    if ( is_single( 18 ) ) {
      wp_enqueue_style( ‘custom-stylesheet’, get_template_directory_uri() . '/style.css' );
     }
    if ( is_single( ‘Hello world’ ) {
        // this will work where post title is ‘Hello world’
        wp_enqueue_style( ‘custom-stylesheet’, get_template_directory_uri() . '/style.css' );
    }
  }
add_action( 'wp_enqueue_scripts', 'webextent_enqueue_styles' );
use of wp_enqueue_script() for specific post
// let’s check we are in the right post
// we can use Post ID or post title
function webextent_scripts() {
 if ( is_page( 34 ) {
     wp_enqueue_script( 'webextent-custom-script', get_template_directory_uri() . '/js/webextent-custom.js', array(), '1.0.0', true );
  }
}
add_action( 'wp_enqueue_scripts', 'webextent_scripts' );

How to enqueue a file for the specific post type

// use of wp_enqueue_script() for specific post type
// let’s check we are in the right post type
// we can use post type slug for that.
function webextent_scripts() {
 if ( get_post_type( get_the_ID() ) == ‘post-type-slug’  ){
     wp_enqueue_script( 'webextent-custom-script', get_template_directory_uri() . '/js/webextent-custom.js', array(), '1.0.0', true );
  }
}
add_action( 'wp_enqueue_scripts', 'webextent_scripts' );
use of wp_enqueue_style() for specific post type

// let’s check we are in the right post type
// we can use post type slug for that.
function webextent_enqueue_styles() {
    if ( get_post_type( get_the_ID() ) == ‘custom-post-type-slug’ ) {
      wp_enqueue_style( ‘custom-stylesheet’, get_template_directory_uri() . '/style.css' );
     }
  }
add_action( 'wp_enqueue_scripts', 'webextent_enqueue_styles' );

Note: You can follow this method for a specific tag or category.

Share:
𝕏 Twitter in LinkedIn

2 responses to “How To Use wp_enqueue_script or wp_enqueue_style For Specific Page, Post or Post Type”

  1. thank you for the page and also the article that you have made is very useful for me and many people who need it.
    greetings from my page writer

Leave a Reply

← Previous Post 10 Important Tips For WordPress Security Next Post → How To Work With WordPress Post Excerpt
You Might Also Like
Why WordPress Updates Matter More Than Most Website Owners Realize
May 11, 2026 WordPress
Why WordPress Updates Matter More Than Most Website Owners Realize

FacebookTweetPinLinkedIn Most websites don’t crash overnight. They quietly fall apart while no one is watching. For thousands of business owners, that slow collapse begins with a single ignored…

Essential Accessibility Tweaks Every WordPress Site Needs Right Now
May 7, 2026 WordPress Guides
Essential Accessibility Tweaks Every WordPress Site Needs Right Now

FacebookTweetPinLinkedIn Why WordPress Accessibility Matters More Than Ever Web accessibility has evolved from a “nice-to-have” feature into a business necessity. Yet over 96% of websites fail basic accessibility…

Stay in the WPExtent Loop

New articles on WordPress, SEO and digital growth — every week.

Discover more from WPExtent

Subscribe now to keep reading and get access to the full archive.

Continue reading