Loading scripts on specific pages only

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

In a future version of the plugin you will be able to limit the pages that the JavaScript and CSS appears on from inside the plugin settings. But for now you will need to do it with custom PHP code.

This requires Quform version 1.5.0 or later.

Only enqueue scripts on a single page/post

Step 1

Get the ID of the post or page that you want to display the Quform JavaScript/CSS on. You can find this number in the browser address bar when editing the post/page.

post-id-url

Step 2

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
34
5
6
7
8
9
10
function my_quform_scripts($enqueue)
{
    if (get_queried_object_id() !== 117) {        $enqueue = false;
    }
 
    return $enqueue;
}
add_filter('iphorm_enqueue_scripts', 'my_quform_scripts');
add_filter('iphorm_enqueue_styles', 'my_quform_scripts');
function my_quform_scripts($enqueue)
{
    if (get_queried_object_id() !== 117) {
        $enqueue = false;
    }

    return $enqueue;
}
add_filter('iphorm_enqueue_scripts', 'my_quform_scripts');
add_filter('iphorm_enqueue_styles', 'my_quform_scripts');
  • On line 3 replace the number 117 with the post ID from Step 1

Enqueue scripts on multiple pages/posts

If you want to limit the plugin JavaScript and CSS to only appear on a few pages, the code is slightly different from above. Instead of checking against a single post ID we will check an array of post IDs.

Step 1

Get the IDs of the posts or pages that you want to display the Quform JavaScript/CSS on. You can find this number in the address bar when editing the post/page.

post-id-url

Step 2

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
34
5
6
7
8
9
10
function my_quform_scripts($enqueue)
{
    if (!in_array(get_queried_object_id(), array(117, 123, 234))) {        $enqueue = false;
    }
 
    return $enqueue;
}
add_filter('iphorm_enqueue_scripts', 'my_quform_scripts');
add_filter('iphorm_enqueue_styles', 'my_quform_scripts');
function my_quform_scripts($enqueue)
{
    if (!in_array(get_queried_object_id(), array(117, 123, 234))) {
        $enqueue = false;
    }

    return $enqueue;
}
add_filter('iphorm_enqueue_scripts', 'my_quform_scripts');
add_filter('iphorm_enqueue_styles', 'my_quform_scripts');
  • On line 3 replace the numbers 117, 123, 234 with the post IDs from Step 1
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy