正在尝试在页脚中注册脚本

时间:2012-10-24 作者:Anders Kitson

我的问题是脚本没有在页脚中注册,它正在消失,尽管jquery.js 确实出现在头部。

我的主题中有以下代码functions.php 文件:

function wptuts_scripts_with_jquery()
{

    // Register the script like this for a theme:
    wp_register_script( \'custom-script\', get_template_directory_uri() . \'/js/jquery.fittext.js\', array( \'jquery\' ), \'\', true );
    // For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( \'custom-script\' );
}
add_action( \'wp_enqueue_scripts\', \'wptuts_scripts_with_jquery\' );
这是我的模板页面的外观:

<?php
/*
Template Name:Tech Basics
*/
?>
<?php get_header( \'tech\' ); ?>

<div id="quote">
    <h1 id="fittext3">Sending you the techie! son you never had.</h1>
</div>
<script type="text/javascript">
        $("#fittext3").fitText(1.1, { minFontSize: 50, maxFontSize: \'75px\' });
    </script>
<div class="row mainContent">
    <div class="twelve columns">
        <?php 
        $page_id = 10; // 123 should be replaced with a specific Page\'s id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be         embedded in the query string of the URL, e.g. page.php?action=edit&post=123.

        $page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.

        echo apply_filters(\'the_content\', $page_data->post_content); // echo the content and retain Wordpress filters such as paragraph tags. Origin from: http://wordpress.org/support/topic/get_pagepost-and-no-paragraphs-problem
?>
    </div>
</div><!--row ends-->
<?php get_footer(); ?>
footer.php:

        </div>
        <!--mainColumns ends-->
    </div>
    <!--main div ends-->
</div>
<!--container ends-->

</body>
</html>

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

你需要wp_footer() 关闭前,请输入页脚body 标签没有它的主题几乎被认为是不完整的,因为像页脚脚本这样的东西没有它就无法工作。

结束

相关推荐

Functions.php:从博客中排除类别

所以很明显,如何从模板中排除某些类别,但我不想修改4个模板,使它们忽略某个类别。有没有一种方法可以将某个类别从阅读设置的“博客”集中排除?我正在将博客分配到名为“博客”的页面。。。但显然,档案和搜索也需要对这一超出类别的内容视而不见。我宁愿在里面做functions.php