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?
- A check for if is parent page, if has children, if has grandchildren
- 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?
- Hide page visual editor if certain template is selected?
- 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?
- How do I modify this page template to show subpage excerpts (not post excerpts)?
- How to inject custom url path for page ?
- Is including the loop necessary for page.php? [duplicate]
- Hide page visual editor if template is selected – redux
- 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)?
- Page template gives ‘Parse error: syntax error’ when used, but no error found!
- more tag in the $post->content when get_pages were used
- how to show all post in my page-grid.php template page
- Different “Text Widgets” in Sidebar on Many Different Pages?
- 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
- How to make certain page templates visible to admin only
- How to move style from template file to section?
- Template for child pages / subpages
- Subpage template
- Include a specific page in your template
- 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?
- Display a specific dynamic sidebar widgets on a specific page
- How to enqueue CSS and JS only on specific template?
- Custom Template 404 for specific custom post type
- Dynamically change page that loads
- 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
- Removing the TinyMCE editor for a given page template
- What’s the best way to manage sections on a page?
- Display grandchild page content on parent page
- 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 output different content of page on different places in my template
- custom page or standalone page?
- How to display time when page is created and edited
- Call a function on every wordpress pages only
- Multiple pages to show posts
- How to finish this loop?
- Specify parent page template
- WP Template Hierarchy – Need help choosing the correct templates
- Auto-Create Pages from Template Directory
- Custom Filter using meta_value in wordpress admin list not working
- Loading custom jQuery and HTML in a WordPress page
- 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
- link a custom page into menu
- Naming custom page templates
- How can I use Page editor for two separate templates?
- Load new Posts on Scroll on Page
- Display random page
- How to read a page’s “Shortcodes” from the Template File?
- exclude page element from specific pages
- if and else statement not working on the iframe php page
- Custom SINGLE page with custom metaboxes and custom template
- I reached halfway through a WordPress tutorial to find out I began wrong for a new comer to WP
- Custom template is not showing up in templates dropdown list after re-naming it
- Site Library issue
- WordPress post-template null warnings