使用wp_footer选项将字符串打印到页脚

时间:2014-05-23 作者:user3378022

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

 function slider_option() { 
   $option ="<script>script function data
                    </script>"; 
    echo $option; 
 }
我要打印,或者您可以说在中插入数据$option 变量到页脚菜单

有什么建议吗?

2 个回复
最合适的回答,由SO网友:Matt Royal 整理而成

脚本是否必须使用变量?

我过去做过这件事,并且一直在努力。。。

// 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\');
如果这不起作用,请确保在主题页脚模板文件中有页脚挂钩。

<?php wp_footer(); ?>

SO网友:user3378022
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 
结束