WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are lot of unused js & stylesheets in my theme.

here is wp_register function in my functions.php

wp_register_script( 'moder',    base_url . 'js/modtom.js', array(), false, false );
wp_register_script( 'videojs',  base_url . 'js/vin.js',    array(), false, false );
wp_register_script( 'selevizr', base_url . 'js/sesin.js',  array('jquery'), false, true );
wp_register_script( 'easi',     base_url . 'js/gmin.js',  array('jquery'), false, true );

wp_register_style( 'styles',     base_url . 'style.css', null, false );

i want these scripts to be run when required or when shortcode use.

share|improve this question
possible duplicate of Where is the right place to register/enqueue scripts & styles – Chris_O Oct 11 '12 at 10:46

You can create a shortcode:

function load_scripts() {

add_shortcode('load_scripts', 'load_scripts');

Then use the shortcode to enqueue the scripts/styles:


Or so:


In terms of running when required, you have to make sure that if you're loading something that requires these, that you either execute the shortcode or enqueue those scripts/styles, since WordPress won't automatically know when you need them.

As a side note, wrap the function either in a class or give it a unique name to avoid collisions.


Shortcode API

do_shortcode function

share|improve this answer
+1, but note it only works for 3.3+ – Stephen Harris Oct 11 '12 at 10:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.