5 min read

Script Logic Plugin

Script Logic Plugin

Last modified

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

  1. Upload plugin to the `/wp-content/plugins/` directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Configure the plugin at `Settings -> Script Logic`
  4. 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

Script Logic Plugin - Load contact form 7 JS files only on contact page

Script Logic Plugin - Load contact form 7 CSS files only on contact page

Step 3:
Dance! You just excluded 2 files from all pages except your contact us page making your site load faster!!!