我想直接从Wordpress插件中排队一串CSS.我不想从外部文件加载它,我不想辩论为什么这是写或错的事情,我只是想知道它是否可能.
换句话说,我知道我可以这样做:
wp_register_style('myStyleSheet', 'my-stylesheet.php');
wp_enqueue_style( 'myStyleSheet');
Run Code Online (Sandbox Code Playgroud)
但我不想.
我想做的是像这样(伪代码):
$number = get_option('some_width')/2;
$css = " .divbox { width: $number; } ";
wp_register_style('myStyleSheet', $css);
wp_enqueue_style( 'myStyleSheet');
Run Code Online (Sandbox Code Playgroud)
我读了wp_register_style()的wp codex,但似乎不可能.有人有建议吗?
那对我来说很傻.几分钟后我找到了答案.绝望是一个很好的动力!:)
诀窍是不使用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' );
Run Code Online (Sandbox Code Playgroud)
不过,也许还有更好的方法吗?
| 归档时间: |
|
| 查看次数: |
3435 次 |
| 最近记录: |