I would like to rewrite quotes characters into the HTML element <q>
.
❌ "Hello world", George said.
✅ <q>Hello world</q>, George said.
The text was written in the WordPress editor and will be displayed in the frontend via the_content()
. In the editor, everything can stay as it is. The output of the quotes should only be changed in the frontend.
My approach is to use a filter to replace the quotes. However, I don’t know how to distinguish between opening and closing quotes.
function quote_filter( $content ) {
$content = preg_replace( ??? );
return $content;
}
add_filter( 'the_content', 'quote_filter' );
Do you have any ideas on how to solve this properly?
4
Answers
I’ll use a for loop, alternating between the opening and closing tag when I reconstruct the string.
BTW, AI would probably say:
You could solve your direct problem as follows:
Of course you can make a function of it and vary what
$myChar
,$prefix
and$suffix
are, potentially adding styling, using other tags or other separators, as you wish.Try this
I have tried this code. It must work for you.
Please let me know if any another query.