twelvell
twelvell

Reputation: 267

How to add multiple templates into if is_page_template?

I have to add multiple template conditions into this code:

if ( is_page_template( 'single.php' ) ) {
wp_enqueue_script( 'google-maps-infobox', get_template_directory_uri() . '/js/gmap3.infobox.js', array( 'jquery' ), '225', true );
wp_enqueue_script( 'google-maps-infobox2', get_template_directory_uri() . '/js/gmap3.infobox2.js', array( 'jquery' ), '225', true );
}

As you see I already added single.php, but it need to add here template1.php, template2.php and so on. I tried it like this:

if ( is_page_template( 'single.php', 'template1.php', 'template2.php' ) ) {
wp_enqueue_script( 'google-maps-infobox', get_template_directory_uri() . '/js/gmap3.infobox.js', array( 'jquery' ), '225', true );
wp_enqueue_script( 'google-maps-infobox2', get_template_directory_uri() . '/js/gmap3.infobox2.js', array( 'jquery' ), '225', true );
}

Unfortunately, this didn`t worked. How do I edit this to enqueue multiple scripts for WordPress pages using these templates?

Regards

Upvotes: 1

Views: 901

Answers (1)

Tristup
Tristup

Reputation: 3663

it should be like this :

if ( is_page_template( 'single.php' ) || is_page_template( 'template1.php' ) || is_page_template( 'template2.php' )) {

//your code goes here
}

Hope this will work for you.

Upvotes: 1

Related Questions