Answer the question
In order to leave comments, you need to log in
How to add text after first h2 and last h2?
Hello! There is such a task - to add a text line to the first h2, the last one, and to the one in the middle. For example, if there are 10 h2 pieces, then after the first, last, and fifth.
Here is the code in WP:
function add_ads_before_h2($content)
{
if (is_single()) {
$div = '<div id="branding3"></div><script type="text/javascript" src="http://r.topdent.ru/show/js.php?id=3&elem=branding3&from=vd"></script>';
$content = preg_replace('/(<h2)/i', $div . '\1', $content, 1);
}
return $content;
}
add_filter('the_content', 'add_ads_before_h2');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question