S
S
Sergey Valitov2015-10-30 13:22:03
PHP
Sergey Valitov, 2015-10-30 13:22:03

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

1 answer(s)
D
Dimonchik, 2015-10-30
@serejatoje

simplehtmldom.sourceforge.net

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question