You have wp_enqueu_script
within your function spelled wrong. It should be wp_enqueue_script
.
Also is_page_template()
will look for your template file as is relative to your theme directory. If file.php is in the root of your theme then it would just be is_page_template('file.php')
. Here is the reference for that function: https://developer.wordpress.org/reference/functions/is_page_template/
Try this:
function test(){
if( is_page_template( 'file.php' ) ){
wp_enqueue_script( 'custom-script', get_template_directory_uri() . 'js/custom.js' );
}
}
add_action( 'wp_enqueue_scripts', 'test' );
Related Posts:
- Dynamically Load Styles and Scripts from Theme Functions.php
- Custom templates not showing up in template dropdown
- Limit number of pages that use a specific template?
- How do I load custom scripts and styles for a page?
- How to dynamically save a selected option from page “Templates” selectbox?
- Custom page template not working
- How do I pass data from page content to the underlying PHP template
- the_content of template page
- Use same page-mypage.php template for several pages
- Avoid pages losing template association on site re-deploy
- WordPress blog posts template bug [closed]
- WordPress form submit to custom page template does not work
- How do you assign custom template for Posts page (under Front page displays setting)
- custom template – override plugin template in child theme – issue with scripts
- Avada Theme – Display results from a specific category [closed]
- how bbPress and buddypress add their own page templates to the page template drop down on the page editing screen
- May I know where to edit the tax rate?
- Get page id by template
- Change page template programmatically ?
- Conditional tag to check if ‘page.php’ is being used?
- How to load JS and CSS only on specific Pages using is_page()?
- Listing pages which uses specific template [duplicate]
- Is there a way to change the default page template selection?
- WordPress page edit does not save selected template
- Is it possible to manipulate the list of page templates?
- Set page template automatically based on parent
- Creating a template using a specific slug name, for a page with a parent page
- Is there a default template file for child pages / subpages?
- Create built-in pages without creating actual pages
- How to display code if it is not certain pages?
- Multiple areas of dynamic content in a page
- How do I set and list page_template with wpcli?
- Add custom admin menu item for pages using a certain template
- WP is not using the select custom template.php that its selected for a page
- Is it possible to set a page template on a dynamic home page (articles list)?
- What’s the most minimal way in which a page can be hooked into WP?
- Why is custom template not seen as page with is_page()?
- Page with page template not using template in Preview
- How do I create multiple page while active a theme
- Template for child pages / subpages
- How to add meta boxes to Pages
- Where can I access my custom page template?
- How do I create a separate page for each author?
- Custom Template 404 for specific custom post type
- Password Protected Page Title
- How do i change page template in bulk?
- Load specific page template based on URI
- I have index.php and other files, how do I display other pages?
- is_home() returns TRUE on page template
- Determine page content based on page parent
- Missing ‘Page Attributes’ in page edit
- How to make tag post listing page working?
- Custom page template with entirely different design. Is it possible in?
- Page template no longer exists – metaboxes won’t save
- Could be a namespace conflict (?) with login form and register form on the same page
- Custom page template for multiple pages
- Remove Content edit box from ALL pages (not posts)
- Get parent of current page
- Custom page with queries returns 404
- How to capture GET argument on static page
- Remove comment section from new page
- WordPress theme: Add page content to the bottom of the Contact form
- WordPress 3.2 – removed ability to select a page template in the page attributes when adding a new page?
- pre-existing data, and entities
- Rewrite to load homepage for a different url
- How do you implement a page template automatically being applied to a page?
- Need to create a custom page on a website
- How to create different template designs for different pages in WordPress [closed]
- Different css file not working for the page template I created
- require_once not working
- Custom form not showing in correct place on page
- Displaying posts on homepage – Template Page
- Page templates in subdirectories and auto generator
- Use page template for custom $_GET content
- creating single page with 2 columns while theme is 3 column
- Using index.php as page template
- Outputting content from page
- How does wordpress link page templates to individual pages
- Static Website No Titles But Still Nav
- Template field missing in page attributes
- My pages are using my Index.php and not my page.php
- WordPress custom pages in a folder
- Different template parts when on different pages
- Create page template
- Updating page template pragmatically
- Using external DB within wordpress
- WordPress Page All Content In Template Good Or Bad Convention?
- display different pages content on single page
- Content template when adding a new page
- How to display time when page is created and edited
- Specify parent page template
- WP Template Hierarchy – Need help choosing the correct templates
- Auto-Create Pages from Template Directory
- different single.php for different page templates
- Showing certain page without redirection
- Create a new page for each form selection
- Using custom post types within a section of a template
- Display random page
- exclude page element from specific pages
- Custom SINGLE page with custom metaboxes and custom template