monakh2
3/11/2020 - 7:46 AM

Add my script where it necessery

function add_my_script_where_it_necessery() {
	global $post;
	if ( is_page() || is_single() ) {
		switch ( $post->post_name ) // post_name is the post slug which is more consistent for matching to here
		{
			case 'site-development':
				wp_enqueue_script( 'vendor', get_stylesheet_directory_uri() . '/js/vendor/vendor.min.js', array( 'jquery' ), '', true );
				break;
			case 'about-page':
				wp_enqueue_script( 'about', get_stylesheet_directory_uri() . '/js/about-page.js', array( 'jquery' ), '', true );
				break;
			case 'some-post':
				wp_enqueue_script( 'somepost', get_stylesheet_directory_uri() . '/js/somepost.js', array( 'jquery' ), '1.6', true );
				break;
		}
	}
}

add_action( 'wp_enqueue_scripts', 'add_my_script_where_it_necessery' );