2
add_action('wp_footer','slider_option');

 function slider_option() { 
   $option ="<script>script function data
                    </script>"; 
    echo $option; 
 }

I want to print or you can say insert data in $option variable to footer menu

Any suggestions?

11
  • Are you trying to load a script? May 23, 2014 at 12:32
  • i want to print inline script to footer which is stored in variable thts it May 23, 2014 at 12:33
  • try the wp_footer hook. codex.wordpress.org/Plugin_API/Action_Reference/wp_footer
    – renny
    May 23, 2014 at 12:34
  • you can also give me solution to inserting inline script to footer will be ok for me May 23, 2014 at 12:34
  • i tried wp_footer hook not working :/ i echo string and also tried return string but both not working May 23, 2014 at 12:35

2 Answers 2

3

Do you have to use a variable for you script?

I have done this in the past and has worked...

// add script to the footer and break out of PHP
function slider_option(){ ?>

<script>script function data</script>

<?php } ?>

add_action('wp_footer','slider_option');

If this does not work make sure you have the footer hook in you themes footer template file.

<?php wp_footer(); ?>
1
0
adding wp_footer() hook inside theme and then this code to add script to footer and worked fine for me 

function slider_option()
    {
    $default=array(     
        'effect'=> 'random',               // Specify sets like: 'fold,fade,sliceDown'
        'slices'=> 15,                     // For slice animations
        'boxCols'=> 8,                     // For box animations
        'boxRows'=> 4,                     // For box animations
        'animSpeed'=> 500,                 // Slide transition speed
        'pauseTime'=> 3000,                // How long each slide will show
        'startSlide'=> 0,                  // Set starting Slide (0 index)
        'directionNav'=> true,             // Next & Prev navigation
        'controlNav'=> true,               // 1,2,3... navigation
        'controlNavThumbs'=> false,        // Use thumbnails for Control Nav
        'pauseOnHover'=> false,             // Stop animation while hovering
        'manualAdvance'=> false,           // Force manual transitions
        'prevText'=> 'Prev',               // Prev directionNav text
        'nextText'=> 'Next',               // Next directionNav text
        'randomStart'=> false);
        extract($default);
        $slider_script;
         ?>  
        <script type='text/javascript'>
                $(window).load(function() {
          $('#slider_slide').nivoSlider({
            effect:<?php echo "$effect"; ?>,
            slices:<?php echo "$slices"; ?>,                     // For slice animations
            boxCols:<?php echo "$boxCols"; ?>,                     // For box animations
            boxRows:<?php echo "$boxRows" ?>,                     // For box animations
            animSpeed:<?php echo "$animSpeed"; ?>,                 // Slide transition speed
            pauseTime:<?php echo "$pauseTime"; ?>,                // How long each slide will show
            startSlide:<?php echo "$startSlide"; ?>,                  // Set starting Slide (0 index)
            directionNav:<?php echo "$directionNav"; ?>,             // Next & Prev navigation
            controlNav:<?php echo "$controlNav"; ?>,               // 1,2,3... navigation
            controlNavThumbs:<?php echo "$controlNavThumbs"; ?>,        // Use thumbnails for Control Nav
            pauseOnHover:<?php echo "$pauseOnHover"; ?>,             // Stop animation while hovering
            manualAdvance:<?php echo "$manualAdvance"; ?>,           // Force manual transitions
            prevText:<?php echo "$prevText"; ?>,               // Prev directionNav text
            nextText:<?php echo "$nextText"; ?>,               // Next directionNav text
            randomStart:<?php echo "$randomStart"; ?>

        });});  
        </script>
    <?php
    }
    add_action('wp_footer','slider_option');
     ?>

thank you for @mattroyal @reny and others  for your help 
1
  • Awesome mate, glad you came right :-)
    – Matt Royal
    May 24, 2014 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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