Wednesday, February 2, 2022

[FIXED] It automatically deletes the <script> tag in the description section of the category

Issue

I tried to use the category description to add schema to the categories, but it automatically deletes the tag after saving it.

is there a way to prevent this in wordpress

enter image description here

after recording;

enter image description here


Solution

For security fields like this tend to be sanitized to prevent random scripts from being injected.

You are better off using wp_enqueue_script or wp_head

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

https://developer.wordpress.org/reference/functions/wp_head/

Using wp_enqueue_script you could check against the category and have it add it that way which also makes it so it only shows up within that/those categories.



Answered By - Mark Truitt

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.