I want to create a function that will capitalize (the first letter of each word is capitalized) in the title of my WordPress site.
I have been able to develop a regular expression for filtering preg_match_all().
The question is how to iterate the matches and capitalize the title using the ucwords() function. Finally, insert the uppercase title into the content.
I tried this code. The question is how to proceed afterif (is_array())
function headings_in_the_content($content) { $regexpattern = '#(?P<(?P h\d)(?P [^>]*)>(?P [^<]*))#i'; if (preg_match_all($regexpattern, $content, $matches)) { foreach ($matches as $regexmatches) { if (is_array($regexmatches)) { foreach ($regexmatches as $regexmatch) { } } } } return $content; } add_filter('the_content', 'headings_in_the_content', 15000);
If it was just for styling purposes, I would use css text-transform instead.
https://developer.mozilla.org/en -US/docs/Web/CSS/text-transform