Introduction
Script Logic is a WordPress plugin that lets you control on which pages scripts and style sheets load using WP’s conditional tags.
This plugin lists all JavaScripts and Style sheets with a control field that lets you control CSS & JavaScript files to include only on the pages where you actually need them. The text field lets you use WP’s Conditional Tags, or any general PHP code.
NOTE: The script logic you introduce is evaluated directly. Anyone who has permission to manage options will have the right to add any code, including malicious and possibly destructive code. There is an optional filter ‘script_logic_eval_override’ which you can use to bypass the EVAL with your own code if needed. (See Other Notes).
Installation
- Upload plugin to the `/wp-content/plugins/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
- Configure the plugin at `Settings -> Script Logic`
- That’s it.
Configuration
On plugin configuration page you see all script and CSS files with a logic field. Lets suppose you are using Contact Form 7 plugin. You created a page Contact Us (slug = contact-us) and want to include Contact Form 7 scripts only on this page. Find the Contact Form 7 scripts on plugin’s configuration page (they have handle = contact-form-7) and put `is_page(‘contact-us’)` in logic field
Usage Example
Lets suppose you are using Contact Form 7 plugin. You created a page Contact Us (slug = contact-us) and want to include Contact Form 7 scripts only on this page.
Step 1:
Find the Contact Form 7 JS and CSS on plugin’s configuration page (they have handle = contact-form-7).
Step 2:
Put is_page('contact-us')
in logic field
Step 3:
Dance! You just excluded 2 files from all pages except your contact us page making your site load faster!!!
This is the one of the plugins i always wanted. Thanks to Tahir Yasin that he put effort to create this plugin. Awesome release. Keep it up!
awesome plugin. makes my pages lighter.
I think this is аmong thе most vital info for me. And i am glad reading your article.
But annа rremɑrk on some general things, The ԝebsite style is perfect, the articles is rеally nice :
D. Good job, cheers
What are these used for and mean…
PHP
Hosting
FTP
SQL
And plugins
PHP (Hypertext Pre Processor) is a server side web scripting language used for developing websites.
Hosting servers are used to host websites. This is where your source code files reside.
FTP (File Transfer Protocol) is used for transferring files.
SQL (Structured Query Language) is used to communicate with databases.
Plugins are little piece of software used to extend functionality of an existing software system.
This is very helpful, thanks for this. Great job Tahir Yasin!
A Big Thanks to Tahir!! ( Great helping hand to figure things out !)
You the man 🙂 !!
Everything works flawlessly.
Thanks…
Farhan
This is one the best which I have seen. I ask to users to use this plugin for their sites.
I cannot thank you enough for the article post.Really thank you! Really Great.
Hi it is giving me an error saying
Fatal error: Unsupported operand types in /wp-content/plugins/script-logic/script-logic.php on line 155
do let me know what the issue can be
Replace the line#155
with
And please let me know if this solves your issue?
Hi nice plugin mate. But I am facing an issue. I am using Coupon Code Lite plugin to display coupons on my WordPress site but it loads the .js file on every page. As suggested above, I have added the is_page(‘deals-2’) condition to load it only on deals page. But even after that, the file is being loaded on all the pages that I checked using GTMetrix and Google Page Speed analyzer. Any idea ?
Bilal, Thanks for liking the plugin.
What is the name of .js file that you couldn’t control with the plugin? Be informed that you can control all JS and CSS files that were included using wp_enqueue_script and wp_enqueue_style functions.
If you are adding script or style tags directly in header/footer then this plugin will not control them.
Handy plugin for everyone. But why don’t you upload your plugin wordpress repository?
Selvam thanks for liking the plugin, its available on WP plugins repo https://wordpress.org/plugins/script-logic/