因此,我在wordpress主题开发和整个网络开发方面都是超级新的,并试图了解WP生态系统。任何帮助都将不胜感激。
在阅读一些WP教程时,我发现有多种方法可以在wordpress中包含style.css文件。即,
<?php bloginfo('stylesheet_url'); ?><?php echo get_stylesheet_uri(); ?><?php echo get_template_directory_uri(); ?>/style.css可以在header.php中添加前3行代码
除此之外,我们还可以使用函数- wp_enqueue_style()。
我的问题是,在wordpress模板中包含style.css的正确方法是什么?
发布于 2017-12-31 15:34:36
我认为使用wp_enqueue_style()是基本的,也是更合适的。
如果希望仅在特定页面模板上引用样式表,则执行以下操作
if ( is_page_template('template-directory/template-name.php')) {
wp_enqueue_style( 'theme_css', get_template_directory_uri() . '/directory/filename.css');
}或者,如果它不是特定于页面模板,您就可以这样做。
wp_enqueue_style( 'theme_css', get_template_directory_uri() . '/directory/filename.css');这段代码需要放在functions.php文件中。在这里阅读更多关于-> https://developer.wordpress.org/themes/basics/including-css-javascript/#stylesheets的信息。
您还需要注意引用css文件-> In which order do CSS stylesheets override?的顺序。
发布于 2017-12-31 15:31:02
一切都会为你工作,在我的想法中没有“正确的方式”。无论如何,使用<?php bloginfo('stylesheet_url'); ?>是因为它是wordpress函数,而且它在head标签中可能会更好。
https://stackoverflow.com/questions/48043657
复制相似问题