Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在WordPress PHP文件中创建内联CSS而不引用外部CSS文件?_Php_Css_Wordpress - Fatal编程技术网

如何在WordPress PHP文件中创建内联CSS而不引用外部CSS文件?

如何在WordPress PHP文件中创建内联CSS而不引用外部CSS文件?,php,css,wordpress,Php,Css,Wordpress,我想直接从Wordpress插件将一个CSS字符串排队。我不想从外部文件加载它,也不想争论为什么这样做是写的还是错的,我只想知道这是否可能 换句话说,我知道我可以做到: wp_register_style('myStyleSheet', 'my-stylesheet.php'); wp_enqueue_style( 'myStyleSheet'); 但我不想 我想做的是这样的事情(伪代码): 我读了wp_register_style()的wp法典,似乎不可能。有人有什么建议吗?我真傻。几分钟后

我想直接从Wordpress插件将一个CSS字符串排队。我不想从外部文件加载它,也不想争论为什么这样做是写的还是错的,我只想知道这是否可能

换句话说,我知道我可以做到:

wp_register_style('myStyleSheet', 'my-stylesheet.php');
wp_enqueue_style( 'myStyleSheet');
但我不想

我想做的是这样的事情(伪代码):


我读了wp_register_style()的wp法典,似乎不可能。有人有什么建议吗?

我真傻。几分钟后我找到了答案。绝望是一个很好的激励因素!:)

诀窍是不要使用wp_register_style()和wp_enqueue_style()

以下是我所做的:

function myStyleSheet() {

  global $value;
  $num = $value/2;

  echo '
       <style type="text/css">
            .divbox { width: '.$num.'; }    
       </style>
    ';
}
add_action( 'wp_print_styles', 'myStyleSheet' );
函数myStyleSheet(){
全球美元价值;
$num=$value/2;
回声'
.divbox{width:'.$num.;}
';
}
添加动作(“wp\u打印样式”、“myStyleSheet”);
不过,也许还有更好的办法

function myStyleSheet() {

  global $value;
  $num = $value/2;

  echo '
       <style type="text/css">
            .divbox { width: '.$num.'; }    
       </style>
    ';
}
add_action( 'wp_print_styles', 'myStyleSheet' );