Move your project_dequeue_unnecessary_scripts()
function to your functions.php
file and add a conditional statement to determine if the appropriate template is being loaded. E.g.:
// Remove Mobile Header
function project_dequeue_unnecessary_scripts() {
if ( is_page_template( 'name-of-template.php' ) ) {
wp_dequeue_script( 'enterprise-responsive-menu' );
wp_deregister_script( 'enterprise-responsive-menu' );
}
}
add_action( 'wp_print_scripts', 'project_dequeue_unnecessary_scripts' );
I suspect that your function is not working because it has been placed somewhere after the call to get_header()
in the template file which means it would be too late to dequeue the script. Declaring functions in template files is not a good practice anyway, so use your functions.php
file or another include.
Related Posts:
- Dequeue Scripts and Style for Mobile not working?
- When using wp_enqueue_script(); in a theme why don’t we use add_action?
- How to enable template page only for a post id page
- enqueue styles for only mobile wp
- Define PHP variable from a seperate API if statement
- Run a jquery script on on a certain template page
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- Advanced method to control cache of enqueued style/script
- WordPress wp_dequeue_script remove all other scripts
- Test CDN link from function.php or wp_enqueue_script/style?
- WP Enqueue Script Error
- Display random categories on the front page (Finding and Editing Theme Functions)
- How to get woocommerce inventory status [closed]
- How to use get_template_directory_uri() to load an image that is in a sub-folder of my theme?
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- Organize functions.php
- How to override functions.php in child theme?
- Most elegant way to enqueue scripts in function.php with foreach loop
- Problem using is_single() to enqueue script from functions.php
- Add inline css to theme
- Enqueuing External Javascript functions.php
- Adjust which tempalte a page uses with a function?
- How to change menu icon which is overriden (i.e. by WooCommerce) [closed]
- Add external js file to footer with id
- How to add background image control to page admin controls?
- Make “sidebar template” the default template for new pages
- Retrieve post modified date for specific post by post ID
- Toggle Sidebar Display
- How do I get a child theme to load scripts from the parent theme?
- How to call custom function from functions.php in site-wide template files?
- Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]
- Attach parent category template to all subcategories
- Add class or ID to any WordPress function
- How to remove howdy dropdown menu content
- Display Password Protected external RSS in wordpress template
- How to extract the variables out from “add_shortcode” function?
- Enqueue scripts not working with if is page conditional tag in functions.php
- wp_is_mobile dequeue not working
- Selective Product Category for Carousel
- How to change login labels
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Modify a function without editing template
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Only let plugin add actions to wp_head & wp_footer on single posts
- how can I edit flexslider in woocommerce. [Urgent]
- Jquery implementation not working on page reload
- Full page template function
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- enqueue_script with filemtime javascript not working
- wordpress use single ajax in place of multiple ajax requests in a smarter way
- Add Element as a Filter to the_content
- Check if the image size is available and if not use ‘full’ image size
- Remove Custuomize Sections
- Need print logo without any ID & class
- Can we create our own theme’s function.php?
- get_pages() Returns Only One Item
- Does size of a theme’s functions.php file matter?
- get_next_posts_link() returns no result despite available posts
- Nav menus all outputting the same links
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Theme JS is available but theme CSS isn’t
- Getting the teaser text without overriding global variables
- Specify multiple categories for custom post template – FATAL ERROR
- Combine two active_callbacks into one on theme customizer
- How to store a number (coming from cookie) into query vars for later usage in other filters?
- What is the correct way to include my new functions and scripts in WordPress?
- wp_nav_menu work in functions.php but not in the theme
- Problem enqueuing scripts on not single posts
- Call two different function.js depending on page
- Enqueueing scripts selectively & activation where needed
- Overwriting TwentyTwelve template file with child theme template, but lower in the hierarchy
- Render page with specific id from functions.php
- How to fix Function create_function() is deprecated in / themes
- the_date() and the_time() functions display actual date an time instead of published date and time
- Is it possible to load recaptcha script only in url with fragment identifier (#)?
- wp_title() return random number
- Why does my wp_enqueue_script() only insert the script for logged in users
- More than one search results page template for two searches on site
- How to retrieve image IDs from shortcode content?
- I need to ‘wp_dequeue_script’ and ‘styles’ and ADD a bunch of other css and js
- I need to completely ‘wp_dequeue_script’; what’s the best way?
- HowTo: Add wrapper to columns shortcode?
- Class::$template_dir_path=get_template_directory();
- Different body image backgrounds on different pages, posts and categories
- Retrieve a custom form field modified by a filter
- How to wp_enqueue_script with html?
- wordpress not calling peliegro functions.php?
- Language switcher for subdomains
- wp_enqueue_script only works outside of action
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- Allow the access over wp-login.php
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- enqueue script if page is not equal to
- Why my wp_enqueue_script doesnt work on some page?
- Add custom css to theme
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- How to get postId from the argument $block when register_block_type()?
- WordPress is adding pagination for all pages not only for blog page, How to remove pagination for all pages except blog/posts page?
- WordPress – Notice: Function wp_enqueue_script was called incorrectly
- dynamically import array from another js file in WordPress