J
J
JefAir2016-03-26 18:03:13
PHP
JefAir, 2016-03-26 18:03:13

How to add div before img in wordpress?

You need to add a div before (or after) every img on a certain page in wordpress (in the content part).
That is, through the standard loader, we insert images on the page, post and see:

<p>
  <a href="#">
    <img class="alignnone wp-image-74 size-full" src="#" alt="" width="300" height="449">
  </a>
  <a href="#">
    <img class="alignnone wp-image-75 size-full" src="#" alt="" width="300" height="449">
  </a>
</p>

And you need:
<p>
  <a href="#">
    <img class="alignnone wp-image-74 size-full" src="#" alt="" width="300" height="449">
    <div class="newdiv"></div>
  </a>
  <a href="#">
    <img class="alignnone wp-image-75 size-full" src="#" alt="" width="300" height="449">
    <div class="newdiv"></div>
  </a>
</p>

Of course, it is necessary that this be automatic, and not be manually registered each time when adding a picture.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-03-26
@JefAir

You can set a filter on 'get_image_tag' and add the desired tag after the image in the function.
But it would be more correct to do as you were advised in another answer - to add this tag through js.

V
Vladimir, 2016-03-26
Khatter @mrKhatter

js, jQuery to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question