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

how can I make the script and style appear in my footer of my wp only when the shortcode is on a page or a post?

share|improve this question

closed as off-topic by Mark Kaplun, Pieter Goosen, birgire, gmazzap, kaiser Sep 28 '14 at 11:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

This isn't based on shortcode detection, but you could try

// Add the Contact Form 7 scripts only on the contact page
function deregister_cf7_js() {
    if ( !is_page('contact')) {
        wp_deregister_script( 'contact-form-7');
add_action( 'wp_print_scripts', 'deregister_cf7_js' );

function deregister_ct7_styles() {
    wp_deregister_style( 'contact-form-7');
add_action( 'wp_print_styles', 'deregister_ct7_styles');

from http://wptheming.com/2009/12/optimize-plug-in-script-wordpress/

I think you could change the wp_print_styles and wp_print_scripts hooks to wp_enqueue_scripts, but I haven't tested that.

I just wrote the following for a custom plugin I am working on:

 * Is User listing?
 * @access public
 * @return boolean
function is_user_listing(){
    global $post;

    $listing = false;

    if( is_page() && isset($post->post_content) && false !== stripos($post->post_content, '[userlist')) {
        $listing = true;

    return apply_filters( 'sul_is_user_listing', $listing );

The premise being that is is searching the post's content for a shortcode that begins with [userlist. Maybe you can adapt it (or at least the conditional) to search for the contact7 shortcode.

share|improve this answer

Script Logic is a WordPress plugin that gives you full control over all JavaScript and CSS files. Using this plugin you can control files to load only on pages where needed.


share|improve this answer

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