Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I do have code that is js script inline together with php script is their possible way to enque it to footer without puting it on .js file

To clear explanition on my question here is my example code

<script>
    $(function(){
        $('#slides').slides({
            preload: <?php echo $option1 ?>,
            generateNextPrev: <?php echo $option2 ?>
        });
                    //some other script 

    });
</script>

Without putting that code in single js, How can I enque it? I see the documentation about enque script usage which only needs 'src'

wp_enqueue_script( 
     $handle
    ,$src
    ,$deps
    ,$ver
    ,$in_footer 
);
share|improve this question
add comment

1 Answer

You can just hook into wp_footer and print out your script.

<?php
add_action('wp_footer', 'wpse64534_script');
function wpse64534_script()
{
    ?>
    <script>
        $(function(){
            $('#slides').slides({
                preload: <?php echo $option1 ?>,
                generateNextPrev: <?php echo $option2 ?>
            });
                        //some other script 

        });
    </script>
    <?php
}
share|improve this answer
    
I tried this metthod with passing variable on function but give me error Missing argument 2 for function name, my function looks like this function wpse64534_script($option1, $option2){ //some code } –  idontknowhow Sep 8 '12 at 4:45
1  
That's because wp_footer doesn't pass any variables to its hooked functions. You need to do some research on how the Hooks api works -- specifically look at how do_action and apply_filters work. If you need variables for elsewhere you can either use globals (bad idea) or use an object (a class) to contain all the related functionality. –  chrisguitarguy Sep 8 '12 at 5:13
add comment

Your Answer

 
discard

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.