I’d put the dequeue statements inside the ‘if’, replacing the $loadscripts line. No need to set the flag and then check the flag to dequeue. That might simplify the code for further debugging.
Edited: suggested code corrections:
function contactform_dequeue_scripts() {
if (is_singular()) {
$post = get_post();
if (has_shortcode($post->post_content, 'contact-form-7')) {
wp_dequeue_script('contact-form-7');
wp_dequeue_script('google-recaptcha');
wp_dequeue_style('contact-form-7');
}
}
}
add_action('wp_enqueue_scripts', 'contactform_dequeue_scripts', 99);
This only dequeue’s scripts if there is a shortcode for CF7, and if it is a singular page. Otherwise, things are done normally. Easier to read the code and figure out what is happening.
Related Posts:
- Contact Form 7: wp_mail doesn’t work after update to 4.6
- How to add a custom tag in contact form 7 and change the output in email?
- Why not to include reference to /wp-admin/admin.php in Plugin
- How do I add a 5 digit ZIP code validation to a Contact7 form?
- how to add contact form 7 shortcode in javascript variable
- How to include PHP files in plugins the correct way
- Prevent network activation of plugin
- How are bulk actions handled in custom list table classes?
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Get list of scripts / styles and show file which enqueued them
- WordPress updates defined vs add_filter?
- Creating Settings Page with dropdowns for Plugin
- How can I track active users of my plugin? and why doesn’t WordPress.Org offer this?
- Empty POST data on server on AJAX request using Angular $http
- Custom Nav Menu items default to ‘menu-item-type’ => ‘custom’. How to make a “page” menu item?
- Custom attachments uploader code. Almost there!
- $wpdb->insert is changing a value
- What are the default WordPress password requirements?
- Can I get all options using the option group id? [closed]
- Actions or filters fired when data is saved in a custom table
- Implementing namespaces in plugin template
- Conditional add_filter?
- The plugin generated 80 characters of unexpected output!
- How to update/auto-update my private plugin? [duplicate]
- How to use WP default post list tables in a plugin?
- What’s the Right Way to get and save remote data for a Gutenberg block?
- Commit changes to WordPress Plugin SVN with TortoiseSVN
- Passing array of strings to a SQL statement in a WordPress plugin
- Add multiple shipping rates from add_rate function with custom ID
- add_shortcode is not working [duplicate]
- Filter, or any way to dynamically change theme screenshot image?
- How to get the post content after WordPress post processing?
- “You do not have sufficient permissions to access this page” upon accessing my newly created plugin page
- Extend a class plugin
- Retrieve contents/page names of various pages for use in a plugin
- How do I dynamically render an InnerBlock inside a dynamic block?
- Does WordPress run install/uninstall functions on plugin upgrade?
- Slow WP_query due to nested wp_query. Need Suggestions
- How can I limit the amount of characters used for description in the manage categories grid?
- How to filter the_content() & include content from template
- Is @wordpress/env locked to node v14 or can I also use node v16?
- ResizableBox with RangeControl not working
- WordPress Custom URL
- Asynchronously render shortcodes in TinyMCE visual editor
- Open modal when user clicks on span in visual editor
- How to paginate a custom page template with custom database tables
- wp_mail() headers multipart/alternative
- What is the proper way to get logged in user id in a plugin?
- WordPress Plugin Activate / Deactive Failing
- How can I add a simple custom field to my plugin?
- Custom Plugin – CSS works, JS doesn’t
- Inserted double quote when prepending to the_content
- unable to wp_enqueue_script(‘suggest’);
- Plugin development – loading Javascript and Flash
- update_post_meta doesnt update template
- Setting global block attribute value
- Plugin custom post template; without overriding all posts
- Run uninstall.php if a checkbox is checked from settings page
- Gravity Forms Anchor only on Front Page?
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- How to set a header in wp_safe_remote_get()?
- Multiple page plugin settings
- sanitizing/escaping plugin options
- how to get the top 10 popular blogs
- can’t access some WordPress function from my plugin
- Custom Block Not Shown in Block Inserter
- add_filter postbox_classes multiple post types
- script seem not load with use wp_enqueue_script
- Impossible to declare box-shadow with wp.customize?
- Do I lose translations when I change my Text domain for my plugin on wp.org?
- WP Refused to display ‘URL’ in a frame because it set ‘X-Frame-Options’ to ‘sameorigin’
- Get search result count in plugin
- Transform internationalized plugin into internationalized mu-plugin?
- Override woocommerce loop-start.php from theme using plugin?
- delete category on plugin deactivation wordpress
- Rate limiting ajax requests in WordPress
- How to filter an action inside class in MemberPress plugin?
- XMLHttpRequest to open PHP file responds with Missing Page
- Pre-populated WooCommerce checkout fields: dropdown fields issue
- jQuery dependent script ignores $in_footer bool and doesn’t work in header
- Relational / Associate tables using native WordPress functionality
- how to retrieve post_id under woocommerce_add_to_cart_validation hook?
- Define a url for an email confirmation from within a plugin
- WordPress Search Form with Keyword Suggestion
- Pull commentdata for pre_comment_on_post from comment_post_ID
- Get the post ID only off single page
- ouput buffering confusing me!
- Bootstrap collapse in custom WordPress widget
- Page reload occurs before request finishes
- PHP Fatal error when using plugin_basename
- How to Rewrite WordPress URL for a Plugin
- append code after the_content not working
- What does $_REQUEST[‘redirect_to’] do?
- how can a plugin return an error message on activation?
- Declaration of mandoe_menu_walker::start_el(&$output, $item, $depth, $args) must be compatible with Walker::start_el(…)
- Reading the inside of
- WordPress, GIT, Renamed Plugin Dir + files – Working Code now Broken [closed]
- Find Any Theme’s page.php File
- WP Job Manager – Show recent jobs as cards
- Admin Menu for New Post