I need some help with targeting a <div>
with preg_replace()
function.
HTML output of the_content()
:
<div class="content">
<link rel="import" href="..." data-target="self">
<div class="content-html contentItem01" id="contentItem001">
<article>
...
</article>
</div>
</div>
I'd like to add a class grid-col3
to the following <div>
<div class="content-html contentItem01" id="contentItem001">
Desired output:
<div class="content-html grid-col3 contentItem01" id="contentItem001">
The code:
$content = the_content();
$content = preg_replace(
'#^(\s*<[^>]+?content-html)#',
'$1 grid-col3',
$content
);
Could you help me to adjust the above code so that it meets my needs? Many thanks!