我有一些wordpress内容,我正在创建一个过滤器,以便它做这样的事情。 下面是wordpress生成的源html文本:
<div id="attachment_210" style="width: 1076px" class="wp-caption alignnone">
<div class="the-image">
<img class="wp-image-210 size-full" src="http://localhost/tiphaine/wp-content/uploads/2016/02/1IMG_0582.jpg" alt="IMG_0582" width="1066" height="1600" />
</div>
<p class="wp-caption-text">
<span class="top-right white">
sweater //
<a href="#">Calvin Klein via Zalando</a>
<br />
skirt //
<a href="#">Gesutz (similar)</a>
<br />
bag //
<a href="#">Burberry via Monnier Frères (budget)</a>
<br />
slip ons //
<a href="#">Ash (similar)</a>
</span>
</p>
现在,如果您注意到,div class="the-image"
标记上有img
。
我想从那里删除这个包装器并用自己包装整个内容。所以最终的结果是这样的:
<div class="the-image">
<div id="attachment_210" style="width: 1076px" class="wp-caption alignnone">
<img class="wp-image-210 size-full" src="http://localhost/tiphaine/wp-content/uploads/2016/02/1IMG_0582.jpg" alt="IMG_0582" width="1066" height="1600" />
<p class="wp-caption-text">
<span class="top-right white">
sweater //
<a href="#">Calvin Klein via Zalando</a>
<br />
skirt //
<a href="#">Gesutz (similar)</a>
<br />
bag //
<a href="#">Burberry via Monnier Frères (budget)</a>
<br />
slip ons //
<a href="#">Ash (similar)</a>
</span>
</p>
</div>
<div class="the-image">
<img class="alignnone size-full wp-image-209" src="http://localhost/tiphaine/wp-content/uploads/2016/02/2IMG_0337.jpg" alt="IMG_0337" width="1066" height="1600" />
</div>
</div>
我对正则表达式不是很好,所以不得不在这里问。