This is because what you’re trying to do trips a security feature, post content is passed through wp_kses_post
to strip out dangerous tags
Administrators however, have the unfiltered_html
capability, which allows them to put arbitrary dangerous HTML in content and titles. This is why you’re able to insert the tags via the editor.
This still doesn’t address the root problem though, that you’re including style tags in post content, which is bad practice, and can cause other issues.
Instead, use shortcodes to embed arbitrary HTML in content, e.g. implement a fluid container shortcode:
[fluidcontainer background="url"][/fluidcontainer]
Or use a CSS HTML solution that does not require a style
tag
As an aside, there is an extremely dangerous solution, that some might suggest, which would be to strip out the security feature. This would be extremely dangerous, and open you up to a large array of attacks. As I have already demonstrated, it is unnecessary. Be very wary of anybody who might suggest it. To do so would be reckless and irresponsible, and on some levels unethical. It could also be used as grounds of technical negligence during compliance, audits, or investigations of data breaches