Wordpress中的函数function.php

时间:2015-10-15 11:36:53

标签: php css wordpress wordpress-theming

我已经开始为Wordpress构建主题了。添加一点我想为网站添加一些样式。我可以在将标题添加到标题时使其工作,但我想使用function.php文件来完成此操作。这就是我得到的:

<?php
function addCss(){
    wp_enqueue_style('style', get_template_directory_uri() . 'style.css');
}

add_action("wp_enqueue_scripts", "addCss");
?>

这是一个非常简单的功能,但由于某种原因,该函数不会被触发。我也没有收到任何错误,并且根据控制台没有将style.css添加到网站。

我的文件结构:

enter image description here

我已经尝试过寻找解决方案,但找不到任何解决方案。我希望你们能帮助我。

3 个答案:

答案 0 :(得分:0)

get_template_directory_uri()返回没有&#34; /&#34的路径;最后。

添加&#34; /&#34;在你的道路上:

// add this line to create a versionning of your stylesheet
$ver = time();
wp_enqueue_style('style', get_template_directory_uri() . '/style.css', $ver);

我希望能帮到你!

答案 1 :(得分:0)

请务必在结束<?php wp_head(); ?>代码之前在header.php中致电</head>

function addMyStyle() {
    wp_enqueue_style( 'my-style', get_template_directory_uri() . '/style.css', false, '1.0', 'all' );

}
add_action('wp_head', 'addMyStyle');

答案 2 :(得分:0)

你需要在header.php

中使用wp_head()
 if ( ! function_exists( 'themescripts' ) ) {
    function themescripts() {
            wp_enqueue_style('style', get_stylesheet_uri(), array());

            wp_enqueue_script( 'jquery', array(), '', true);
            ....
        }

    add_action( 'wp_enqueue_scripts', 'themescripts' ); 
}

另外,请确保在footer.php文件中包含wp_footer()。

相关问题