Any ideas what might be wrong with this regex - it doesn't seem to find anything:
function ad_content($content) {
if (is_single()) {
$find = '#<div id=\"attachment_(\d+)\" class=\"wp-caption aligncenter\" style=\"width: (\d+)px\">(.*?)</div>#s';
$replace1 = '11111';
$content = preg_replace($find,$replace,$content,1);
}
return $content;
}
add_filter ('the_content','ad_content');
I've tried with something basic like
$find = '#attachment#';
and that does work.
When I use the above regex it doesn't replace anything, and gives no errors either. Thus, I suppose it just doesn't find anything. Here's what it should find:
<div id="attachment_167" class="wp-caption aligncenter" style="width: 600px"><a href="http://www.url.com"><img class="size-full wp-image-167" alt="text" src="http://www.url.com" width="600" height="776" /></a><p class="wp-caption-text">text – text</p></div>
I've tried it at this regex validator and it does match.
ANSWER:
I think I've finally figured it - the_content hook, doesn't seem to apply to my div. Simple as that.