我对用WordPress创建主题比较陌生,我一直在用旧的echo get_stylesheet_uri();
. 但我发现这不是推荐的方法,而是在函数中添加所有样式。php。
旧方法(工作):
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">
新方法(不工作):<?php
add_theme_support(\'post-thumbnails\'); //Posts thumbnails
//Custom excerpt
function get_excerpt($excerpt, $length, $more_char = \'...\'){
return mb_strimwidth($excerpt, 0, $length, $more_char);
}
function theme_styles() {
//METHOD 1
//wp_register_style( \'main-style\', get_template_directory_uri() . \'/style.css\');
//wp_enqueue_style( \'main-style\');
//METHOD 2
wp_enqueue_style( \'main-style\', get_template_directory_uri() . \'/style.css\' );
}
add_action( \'wp_enqueue_scripts\', \'theme_styles\' );
?>
我尝试了上述两种方法,但都没有奏效。除了我的英语不好之外,还有什么问题吗?<小时>
Edit (SOLVED)
幸亏Nathan Johnson 谁发现了错误。我没有使用wp_head()
在我的header.php
, 因此,WordPress找不到将排队样式放在哪里。新手错误。