如何从functions.php将以下css代码添加到我的页面标题?
现在,我将以下代码放在如何从functions.php将以下css代码添加到我的页面标题?,css,wordpress,function,Css,Wordpress,Function,现在,我将以下代码放在header.php中 我认为这个解决方案不是很优雅 如何将functions.php中的CSS代码添加到我的标题中(该代码看起来如何) wp_头(); ?> .Jimgul li.a{ 背景:url(/images/)重复滚动0%; } .Jimgul li.人民a{ 背景:url(/images/)重复滚动0%; } .Jimgul li.nature a{ 背景:url(/images/nature.jpg)重复滚动0%; } a.Jimgul li.摘要a{ 背景:
header.php
中
我认为这个解决方案不是很优雅
如何将functions.php
中的CSS代码添加到我的标题中(该代码看起来如何)
wp_头();
?>
.Jimgul li.a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.人民a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.nature a{
背景:url(/images/nature.jpg)重复滚动0%;
}
a.Jimgul li.摘要a{
背景:url(/images/abstract.jpg)重复滚动0%;
}
Jimgul li.urban a{
背景:url(/images/urban.jpg)重复滚动0%;
}
.Jimgul li.人民2 a{
背景:url(/images/people.jpg)重复滚动0%;
最小宽度:310px;
}
您不能调用它,但可以将其作为css插入:
<link href="generate-css.php" type="text/css" rel="stylesheet" />
您不能调用它,但可以将其作为css插入:
<link href="generate-css.php" type="text/css" rel="stylesheet" />
您可以轻松地将CSS包装到函数中
function headerCSS(){
?>
// YOUR CSS
<?php
}
函数headerCSS(){
?>
//你的CSS
//这里还有其他标题
您可以轻松地将CSS包装到函数中
function headerCSS(){
?>
// YOUR CSS
<?php
}
函数headerCSS(){
?>
//你的CSS
//这里还有其他标题
这是一个糟糕的解决方案。外部样式表是由服务器缓存的。您使用的方法意味着它们必须在每个页面中提供,并且在服务器端资源更密集
请看使用标记来设置站点资源路径
基本标记对于Web应用程序非常有用
在一个网站中创建网站的设计师
但最终将被放置在
在另一个地方
请参阅:这是一个糟糕的解决方案。外部样式表由服务器缓存。您使用的方法意味着它们必须在每个页面中提供,并且在服务器端更占用资源
请看使用标记来设置站点资源路径
基本标记对于Web应用程序非常有用
在一个网站中创建网站的设计师
但最终将被放置在
在另一个地方
请参阅:@janoChen:假设您的目录结构如下所示
/wp-content/
/themes/
/your_theme/
/images/
将所有不带
的样式放在/wp content/themes/your_theme/
中的style.css文件中,然后放在标题中。php
只需
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles.css" media="screen" type="text/css" />
@janoChen:假设您的目录结构如下所示
/wp-content/
/themes/
/your_theme/
/images/
将所有不带
的样式放在/wp content/themes/your_theme/
中的style.css文件中,然后放在标题中。php
只需
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles.css" media="screen" type="text/css" />
使用钩子是最好的方法-然后您只需修改functions.php,而不必修改模板,这样在作者发布更改、更新或修补程序时更容易更新模板
functions.php
<?php
function add_styles()
{
?>
<style type="text/css">
.jimgMenu ul li.landscapes a {
background: url(<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'intro_image'); ?>) repeat scroll 0%;
}
.jimgMenu ul li.people a {
background: url(<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'slider_image'); ?>) repeat scroll 0%;
}
.jimgMenu ul li.nature a {
background: url(<?php bloginfo('template_directory'); ?>/images/nature.jpg) repeat scroll 0%;
}
.jimgMenu ul li.abstract a {
background: url(<?php bloginfo('template_directory'); ?>/images/abstract.jpg) repeat scroll 0%;
}
.jimgMenu ul li.urban a {
background: url(<?php bloginfo('template_directory'); ?>/images/urban.jpg) repeat scroll 0%;
}
.jimgMenu ul li.people2 a {
background: url(<?php bloginfo('template_directory'); ?>/images/people.jpg) repeat scroll 0%;
min-width:310px;
}
</style>
<?php
}
add_action('wp_head', 'add_styles');
.Jimgul li.a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.人民a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.nature a{
背景:url(/images/nature.jpg)重复滚动0%;
}
a.Jimgul li.摘要a{
背景:url(/images/abstract.jpg)重复滚动0%;
}
Jimgul li.urban a{
背景:url(/images/urban.jpg)重复滚动0%;
}
.Jimgul li.人民2 a{
背景:url(/images/people.jpg)重复滚动0%;
最小宽度:310px;
}
使用钩子是最好的方法-然后您只需修改functions.php而不需要修改模板,这样在作者发布更改、更新或修补程序时更新模板就更容易了
functions.php
<?php
function add_styles()
{
?>
<style type="text/css">
.jimgMenu ul li.landscapes a {
background: url(<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'intro_image'); ?>) repeat scroll 0%;
}
.jimgMenu ul li.people a {
background: url(<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'slider_image'); ?>) repeat scroll 0%;
}
.jimgMenu ul li.nature a {
background: url(<?php bloginfo('template_directory'); ?>/images/nature.jpg) repeat scroll 0%;
}
.jimgMenu ul li.abstract a {
background: url(<?php bloginfo('template_directory'); ?>/images/abstract.jpg) repeat scroll 0%;
}
.jimgMenu ul li.urban a {
background: url(<?php bloginfo('template_directory'); ?>/images/urban.jpg) repeat scroll 0%;
}
.jimgMenu ul li.people2 a {
background: url(<?php bloginfo('template_directory'); ?>/images/people.jpg) repeat scroll 0%;
min-width:310px;
}
</style>
<?php
}
add_action('wp_head', 'add_styles');
.Jimgul li.a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.人民a{
背景:url(/images/)重复滚动0%;
}
.Jimgul li.nature a{
背景:url(/images/nature.jpg)重复滚动0%;
}
a.Jimgul li.摘要a{
背景:url(/images/abstract.jpg)重复滚动0%;
}
Jimgul li.urban a{
背景:url(/images/urban.jpg)重复滚动0%;
}
.Jimgul li.人民2 a{
背景:url(/images/people.jpg)重复滚动0%;
最小宽度:310px;
}
要“调用”某个东西,它必须在一个函数中,或者在它自己的文件中,你可以include()
或者require()
。要“调用”某个东西,它必须在一个函数中,或者在它自己的文件中,你可以include()
或者require()
。谢谢,我想钩子就是答案。谢谢,我想钩子就是答案。