admin管理员组文章数量:1414621
I'm looking at customising the embeds of posts for a theme I am creating. Looking at header-embed.php
in Theme_Compat
I see that the head has the following class="no-js"
.
Does this mean that including JavaScript would be a bad idea? (If so why?)
I'm looking at customising the embeds of posts for a theme I am creating. Looking at header-embed.php
in Theme_Compat
I see that the head has the following class="no-js"
.
Does this mean that including JavaScript would be a bad idea? (If so why?)
Share Improve this question asked Sep 15, 2019 at 15:58 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges1 Answer
Reset to default 1Does this mean that including JavaScript would be a bad idea?
No, it doesn't.
That class is used for styling purposes so that you could apply styles specific to when JavaScript is not available (either not supported or is disabled), and when it's available (supported and enabled). And in most cases/implementations, when JS is enabled, the no-js
class will be replaced with js
. (I mean, you can use another name, if you want to...)
/* Sample CSS. Allows you to have something like:
<p class="hide-if-js">Hidden if JS is enabled</p>
<p class="hide-if-no-js">Hidden if JS is not enabled</p>
*/
.js .hide-if-js,
.no-js .hide-if-no-js {
display: none;
}
And for the WordPress post embeds, here's the code which replaces the class name — but only if certain conditions are met (e.g. window.addEventListener
is supported by the browser):
document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/, '' ) + ' js';
In fact, WordPress admin pages also use the same trick and you can see the relevant code in wp-admin/admin-header.php
:
<body class="wp-admin wp-core-ui no-js <?php echo $admin_body_classes; ?>">
<script type="text/javascript">
document.body.className = document.body.className.replace('no-js','js');
</script>
本文标签: theme developmentIS there any reason not to include javascript in my own post39s embeds
版权声明:本文标题:theme development - IS there any reason not to include javascript in my own post's embeds? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745155923a2645170.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论