Normally, in WYSIWYG/Body content, if you use 'apostrophes' it will automatically convert these to left/right single quotes. Most people around the internet don't want this. But in the case I DO!
When using a Single Line Field, there is no such wptexturize conversion. But I need this to happen. I can't get my users to input with special characters, and the apostrophes aren't look good.
SO:
Is there a function I can use to do this conversion? The 1st apostrophe would need to become a left single quote, and the second a right single quote. Plus, added bonus, if there is a second set also convert that.
Any thoughts on fixing this?
(I also don't want to use a WYSIWYG field because it's way too big and cumbersome and opens up many other new issues of what people might input incorrectly)
THANK IN ADVANCE!
Hello,
There isn't such a built-in feature within Toolsets, it needs custom codes, for example you can try these:
1) When user input text into custom single line field, and save the post, Use WordPress action hook save_post to trigger a custom PHP function:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
2) In the custom PHP function, get the custom single line field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
And change it to what you want:
https://developer.wordpress.org/reference/functions/update_post_meta/
Hi Luo,
Thank you for the links. I already understand those items (although direct reference links are always helpful since it's been a while).
Other than me running preg replace, do you think there is another option? Such as somehow connect into wptexturize? I've never dealt with that before and perhaps you can point me towards the correct approach.
There is a built-in function wptexturize() within WordPress core:
https://developer.wordpress.org/reference/functions/wptexturize/
Replaces common plain text characters into formatted entities
You can use it to change the text, in the step 2) I mentioned in post:
https://toolset.com/forums/topic/single-line-fields-remove-wptexturize-on-single-quotes-apostrophes/#post-629893
For your reference.