Title: Enqueue scripts and CSS files only in pages that include shortcode
Last modified: October 21, 2020

---

# Enqueue scripts and CSS files only in pages that include shortcode

 *  [capbussat](https://wordpress.org/support/users/capbussat/)
 * (@capbussat)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/enqueue-scripts-and-css-files-only-in-pages-that-include-shortcode/)
 * I am trying to** enqueue SCRIPTS and CSS files of CF7 only for pages where shortcode
   appears** as to improve Page Speed rankings.
    My aproximation would be to register
   scripts and css previously but only ENQUEUE them from inside the shortcode function.
   I am using this approach in another plugin, and it works for me.
    - First I register scripts and styles with
    - wp_register_script(‘my-script’,’my_script.js’) or wp_register_style(‘my-style’,‘
      my_style.css’) inside an action’wp_enqueue_scripts’.
    -  Second , I am using wp_enqueue_script(‘my-script’) and wp_enqueue_style(‘
      my-style’) inside my shortcode and it works.
 * My question is if could not be possible to update CF7 to accomplish the same?
   
   Thanks in advance.
    -  This topic was modified 5 years, 7 months ago by [capbussat](https://wordpress.org/support/users/capbussat/).
    -  This topic was modified 5 years, 7 months ago by [capbussat](https://wordpress.org/support/users/capbussat/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/enqueue-scripts-and-css-files-only-in-pages-that-include-shortcode/#post-13562665)
 * See [Loading JavaScript and stylesheet only when it is necessary](https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/)
 *  Thread Starter [capbussat](https://wordpress.org/support/users/capbussat/)
 * (@capbussat)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/enqueue-scripts-and-css-files-only-in-pages-that-include-shortcode/#post-13562767)
 * Yes. Thanks.
    I read this information but I do not like this solution. It does
   not seem easy and effective solution to me to change two files of all websites
   that use your plugin to avoid loading two extra files for all websites that use
   your plugin. It may be another way.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Enqueue scripts and CSS files only in pages that include shortcode’ is
closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [capbussat](https://wordpress.org/support/users/capbussat/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/enqueue-scripts-and-css-files-only-in-pages-that-include-shortcode/#post-13562767)
 * Status: not a support question