• I’ve written a few plugins so I know my way around WordPress, but I’m trying to do something just now and have a lot of trouble with it.

    I want to include some javascript code on every page that includes a shortcode. I’m currently attempting it using this code:

    <?php
    
    add_shortcode('theshortcodehere', 'wbbb_shortcodes');
    
    function wbbb_shortcodes($atts){
    	return 'Hello There.';
    	add_action('wp_head','wbbb_echohead');
    }
    
    function wbbb_echohead(){
    	echo '<script type="text/javascript"><!-- Lots of JavaScript here--></script>';
    }
    
    ?>

    So what should happen is the shortcode should activate the wbbb_shortcodes() function which in turn adds the javascript wp_head action. Unfortunately it doesn’t trigger. The shortcode works and returns Hello There. but the javascript isn’t included in the head section (I am viewing the generated HTML source).

    What am I doing wrong, or is there an easier way to accomplish this?

    Cheers

Viewing 1 replies (of 1 total)
  • Thread Starter Seans0n

    (@seans0n)

    I tried echoing out the javascript in place of the shortcode, but unfortunately it needs to go between the head tags.

    Anyone have any ideas on how I could do this? I.e. place some javascript between the head tags of any page or post which has [theshortcodehere] on it?

Viewing 1 replies (of 1 total)
  • The topic ‘Trying To Do This – Please Help’ is closed to new replies.