最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Can `<style>` and `<script>` tags be used in the HTML editor?

programmeradmin0浏览0评论

I understand this is so stupid, because absolutely there should be an answer out there, but I can't find it myself. In short, can you use <style> and <script> tags in the HTML editor, without any plugin or touching the style.css file? I am an author of a blog I don't own, and I would like to add custom styles on my articles. I try it and it seems that it doesn't work, but I would like to have a definite answer.

I understand this is so stupid, because absolutely there should be an answer out there, but I can't find it myself. In short, can you use <style> and <script> tags in the HTML editor, without any plugin or touching the style.css file? I am an author of a blog I don't own, and I would like to add custom styles on my articles. I try it and it seems that it doesn't work, but I would like to have a definite answer.

Share Improve this question asked Oct 2, 2019 at 18:38 OokerOoker 3324 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Mostly no, but you shouldn't do that anyway.

The exception, is if your user has the unfiltered_html capability, which is a dangerous power to have. Users that have this are admins on a single site install, or a super admin on a multisite install.

But, there are major security downside to putting script and style tags directly into articles.

For CSS, it's unnecessary, the customizer has a built in CSS editor. If your theme is built correctly, the body tag and main article/post tag will have IDs and classes you can use to target specific posts

For Javascript, this should be in the theme or a plugin. Entering javascript into the database opens up a security can of worms. If you must do it, do it via a custom field and some code, or a plugin. Don't do it via post content

发布评论

评论列表(0)

  1. 暂无评论