• I have a php function that needs to take in 5-6 arguments from a shortcode. Those arguments are for adding php variables into a javascript code. I want that javascript code to be added to just before the body tag ends. So to do this I need to add an action to wp_footer.

    add_action('wp_footer', 'example_function', $var1, $var2, $var3, $var4, $var5);

    This code does not really work, I have that in my shortcode function. The shortcode itself works perfect!

    The codex says:
    <?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?>

    So it can accept arguments, but I have just seen examples with 1 argument and not several which is needed in my case. Anyone know how I can achieve this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Icethrill

    (@icethrill)

    At the moment I have this:

    do_action('wp_footer', $var1, $var2, $var3, $var4, $var5);
    add_action('wp_footer', 'example_function', 0, 5);

    It works fine for one instance, but there might be X instances of this script running. Anyone that can help me further with this?

    Thread Starter Icethrill

    (@icethrill)

    Well my mistake, it didnt work for one instance either…

    Thread Starter Icethrill

    (@icethrill)

    Anyone?

    Thread Starter Icethrill

    (@icethrill)

    Feels like I am spamming, but I still havent resolved this and need some expert help.

    Gonna try to explain it a little more. I have a shortcode function in my plugin, that adds a script element and a div container to the post/page. In the WYSIWYG I have added a button to the Tiny MCE that opens a popup page of settings. The settings selected will be added to a shortcode in the content with several arguments defined to it.

    The data in the shortcode is used as variables in the javascript and width/height of the div container. As it is now the code will create a script tag and a div container.

    <script type="text/javascript">
    //  Lots of JS code is here
    </script>
    <div id="container-id" style="height:500px; width:100%;"></div>

    The script populates the container will lots of new information. I want to add the script to wp_footer and along with it all the arguments. Like this:

    <div id="content">
    <div id="container-id" style="height:500px; width:100%;"></div>
    </div><!-- #content -->
    <script type="text/javascript">
    //  Lots of JS code is here right before the body tag ends.
    </script>
    </body>

    To achieve this I need to use actions, like add_action and do_action. This is where the code above comes in the picture. I am not able to replicate what I want.

    Thankful for any help at all. This is an real headache for me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add arguments into an add_action() call?’ is closed to new replies.