admin管理员组文章数量:1022467
We have some shortcodes which are generating CSS styles. there are like options ("Title color, Title box border color,font-size, font-weight").
When user setup the options, it will be generated before the shortcode code started.
ex)
<html>
<head>
.................. (some style, js) ..................
/* I want to put all of css styles into head tag from into body tags */
</head>
<body>
<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>
<div class="sc_wrap">
<h1 class="sc_title">Hello This is the title</h1>
</div>
</body>
</html>
As you may know this is illegal rule for W3C. style tags have to be in "head" tag.
Is there anyway to put them into header tags when css styles have been generated from shortcodes?
I have seen some tips or tutorial saying that I should use wp enqueue style. I don't think it's possible to create each .css files for each shortcodes.
Please advise us if we have missed something or if you have any good idea.
Thank you,
We have some shortcodes which are generating CSS styles. there are like options ("Title color, Title box border color,font-size, font-weight").
When user setup the options, it will be generated before the shortcode code started.
ex)
<html>
<head>
.................. (some style, js) ..................
/* I want to put all of css styles into head tag from into body tags */
</head>
<body>
<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>
<div class="sc_wrap">
<h1 class="sc_title">Hello This is the title</h1>
</div>
</body>
</html>
As you may know this is illegal rule for W3C. style tags have to be in "head" tag.
Is there anyway to put them into header tags when css styles have been generated from shortcodes?
I have seen some tips or tutorial saying that I should use wp enqueue style. I don't think it's possible to create each .css files for each shortcodes.
Please advise us if we have missed something or if you have any good idea.
Thank you,
Share Improve this question asked Sep 7, 2015 at 10:30 pullapulla 7235 gold badges17 silver badges34 bronze badges 1- 2 Possible duplicate of Enqueue Scripts / Styles when shortcode is present – norman.lol Commented May 17, 2019 at 10:16
1 Answer
Reset to default -1You can insert any code in the header by hooking an action.
header.php
<?php wp_head(); ?>
functions.php
add_action( 'wp_head', 'iulia_example' );
function iulia_example() {
echo '<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>';
}
the result will be : the style inserted just above </head>
We have some shortcodes which are generating CSS styles. there are like options ("Title color, Title box border color,font-size, font-weight").
When user setup the options, it will be generated before the shortcode code started.
ex)
<html>
<head>
.................. (some style, js) ..................
/* I want to put all of css styles into head tag from into body tags */
</head>
<body>
<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>
<div class="sc_wrap">
<h1 class="sc_title">Hello This is the title</h1>
</div>
</body>
</html>
As you may know this is illegal rule for W3C. style tags have to be in "head" tag.
Is there anyway to put them into header tags when css styles have been generated from shortcodes?
I have seen some tips or tutorial saying that I should use wp enqueue style. I don't think it's possible to create each .css files for each shortcodes.
Please advise us if we have missed something or if you have any good idea.
Thank you,
We have some shortcodes which are generating CSS styles. there are like options ("Title color, Title box border color,font-size, font-weight").
When user setup the options, it will be generated before the shortcode code started.
ex)
<html>
<head>
.................. (some style, js) ..................
/* I want to put all of css styles into head tag from into body tags */
</head>
<body>
<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>
<div class="sc_wrap">
<h1 class="sc_title">Hello This is the title</h1>
</div>
</body>
</html>
As you may know this is illegal rule for W3C. style tags have to be in "head" tag.
Is there anyway to put them into header tags when css styles have been generated from shortcodes?
I have seen some tips or tutorial saying that I should use wp enqueue style. I don't think it's possible to create each .css files for each shortcodes.
Please advise us if we have missed something or if you have any good idea.
Thank you,
Share Improve this question asked Sep 7, 2015 at 10:30 pullapulla 7235 gold badges17 silver badges34 bronze badges 1- 2 Possible duplicate of Enqueue Scripts / Styles when shortcode is present – norman.lol Commented May 17, 2019 at 10:16
1 Answer
Reset to default -1You can insert any code in the header by hooking an action.
header.php
<?php wp_head(); ?>
functions.php
add_action( 'wp_head', 'iulia_example' );
function iulia_example() {
echo '<style type="text/css">
.sc_title {color:#fff; font-weight:600;}
</style>';
}
the result will be : the style inserted just above </head>
本文标签: style css to header for shortcodes
版权声明:本文标题:style css to header for shortcodes 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745484699a2152690.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论