Learn how to make ContactForm7 js and css load only on specified pages in WordPress without using a plugin.
Normally, when ContactForm7 is installed, js and css are loaded on every page, which slows down the display speed, but this can be prevented by using this method.
Edit functions.php.
If a child theme is available, use the child theme’s functions.php.
※Always make a backup before editing.
If only one page is to be loaded.
function deregister_cf7_files() {
if ( ! is_page(page ID) ) {
wp_dequeue_style( 'contact-form-7' );
wp_dequeue_script( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'deregister_cf7_files' );
Easier code.
If you only want to load pages with the page slug ‘contact’, do the following
Enter any slug in the ‘contact’ part of the second line.
add_action( 'wp', function() {
if ( is_page( 'contact' ) ) return;
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
});
If there is more than one page to be loaded.
function deregister_cf7_files() {
if ( ! is_page(array('page ID1','page ID2')) ) {
wp_dequeue_style( 'contact-form-7' );
wp_dequeue_script( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'deregister_cf7_files' );
Conclusion.
I have used the above code for “multiple pages to load” from the beginning, in case there will be more contact pages later on.
The work itself does not take long and can be implemented quickly, so please refer to this if you like.
Thank you for watching until the end.
Plant
Agave victoriae-reginae ‘Sasanoyuki’
1. Basic Information.1.1. Scientific name1.2. Family name1.3. Genus name1.4. Species name1.5. Country of origin1.6. Habitat1.7. Morphology1.8. Mature tree1.9. Cold hardy1.10. Heat tolerant1.11. Sunshine1.12. Flour color1.13. Flowering period Basic Information. Scientific name Agave victoria-regina Family name Asparagaceae Genus name Agave Species...
Continue readingArrival Shop
Accession in December 2024
More will appear in December! Pre-orders are also available.We hope you will order as soon as possible if you wish, as numbers are limited.
Continue readingCode Speed Web Without Plugin Wordpress
Without plugins!How to use syntax highlighting Prism.js.|WordPress
In this article, we will show you how to implement syntax highlighting in WordPress without using a plugin. Syntax highlighting is often used to display source code on websites and blog sites. This website has adopted “Prism.js” after various trials....
Continue readingCDN Security Speed
DNS configuration with Cloudflare.Set up bombastic DNS for a more comfortable IT life.
DNS configuration with Cloudflare not only speeds up browser start-up, but also contributes to improved security. Please give it a try. 1. 1.1.1.12. 1.1.1.1 family oriented.2.1. Blocks malware.2.2. Blocks malware and adult content. 1.1.1.1 1.1.1.1 is Cloudflare’s public DNS resolver.It...
Continue readingNews NGO
Non-governmental organization established.「DAIKICI NGO」
Today, the non-governmental organisation “DAIKICI NGO” was established. The aim is to grow and advance humanity while working to solve problems across the globe, whether local, national or international. There are many problems and challenges, but we want to work...
Continue readingPlant
Obregonia denegrii.
One genus and one species of cactus, so majestic and dignified is its appearance that it is known as the ‘TEIKAN’. This is a very rare cactus and one of the most popular cacti, partly because of its beautiful rosette...
Continue readingSpeed Web
Image compression web tool to accelerate website display speed.
There are several ways to improve the display speed of a website, the first effective way is to optimise the size of images. In such cases, it is recommended to use the following image compression web tools. The advantage is...
Continue readingCode Web Without Plugin Woocommerce Wordpress
Without Plugin!How to display just any item on the Woocommerce My Account page.
The items on the Woocommerce My Account page vary depending on the products handled and the site they are on. For example, if you want to hide the ‘Dashboard’ and ‘Downloads’ items, you can achieve this by doing the following....
Continue readingPlant Raise
The key points are sun, wind, water and soil! How to grow succulents.
Succulents are very easy to grow compared to other plants. There are four simple points. Maintain in a sunny location. Maintain in a well-ventilated area. Water when the soil is dry. Plant in well-drained soil. As long as the above...
Continue readingCode Security Web Wordpress
How to hide information in php.ini.WordPress
Hiding php.ini information improves site security. You are encouraged to refer to this information to maintain your website. 1. Description in the ‘php.ini’ file.2. In “.htaccess” files. Description in the ‘php.ini’ file. display_errors = off In “.htaccess” files. <Files php.ini>...
Continue reading