I have a custom theme with just a name in its style.css
. I\'ve activated it in admin which shows it just fine.
In the index.php
just <?php wp_head(); ?>
and it doesn\'t output the line that is supposed to include my main stylesheet style.css
:
<link rel=\'stylesheet\' id=\'my-theme\' href=\'~/wp-content/themes/my-theme/style.css\' type=\'text/css\' media=\'all\' />
It prints out all the other stuff but that line! What would make it not print out my default stylesheet inclusion line?
style.css
:
/*
Theme Name: my-theme
*/
index.php
:
hello world
<?php wp_head(); ?>
output:
hello world
<meta name=\'robots\' content=\'noindex,follow\' />
<link rel=\'stylesheet\' id=\'open-sans-css\' href=\'//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=4.0\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'dashicons-css\' href=\'~/wp-includes/css/dashicons.min.css?ver=4.0\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'admin-bar-css\' href=\'~/wp-includes/css/admin-bar.min.css?ver=4.0\' type=\'text/css\' media=\'all\' />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="~/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="~/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 4.0" />
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css" media="screen">
html { margin-top: 32px !important; }
* html body { margin-top: 32px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 46px !important; }
* html body { margin-top: 46px !important; }
}
</style>
SO网友:Nicolai Grossherr
实际上,您不应该将JS和CSS文件添加到header.php
, 但要利用这些功能wp_enqueue_script()
和wp_enqueue_style()
将它们添加到那里。
来自codex页面的示例:
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( \'style-name\', get_stylesheet_uri() );
wp_enqueue_script( \'script-name\', get_template_directory_uri() . \'/js/example.js\', array(), \'1.0.0\', true );
}
add_action( \'wp_enqueue_scripts\', \'theme_name_scripts\' );
SO网友:Robert hue
您应该添加您的。js和。css文件,如下所示。在您的header.php
<link rel=\'stylesheet\' id=\'my-theme\' href=\'<?php echo get_template_directory_uri(); ?>/style.css\' type=\'text/css\' media=\'all\' />
你注意到了吗
<?php echo get_template_directory_uri(); ?>
在上面的代码中,您将需要使用。它定义了网站上主题文件夹的URL。您可以类似地添加所有其他文件链接。
虽然没有必要包含/主题/样式。css在你的网站上,除非它有任何样式供网站使用。我认为你的主题使用这种风格。css文件仅供参考/定义主题变量之用。