Có thể bạn quan tâm
Bình thường khi thêm ảnh, WordPress sẽ tự động thêm thẻ <p> xung quanh thẻ <img>.
Ví dụ:
blah blah blah
<img src="monkey.jpg">
blah blah blah
Khi xuất ra bài viết:
<p>blah blah blah</p> <img src="monkey.jpg"> <p>blah blah blah</p>
Chúng ta có thể fix nó bằng hàm sau. Thêm hàm này vào file functions.php của theme nhé
//Xóa thẻ <p> xung quanh thẻ <img> function filter_ptags_on_images($content){ return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); } add_filter('the_content', 'filter_ptags_on_images');
Sau khi xóa chúng ta sẽ được:
<p>blah blah blah</p> <img src="monkey.jpg"> <p>blah blah blah</p>
Chúc các bạn thành công!
Tham khảo thêm : https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
Từ khóa: wordpress
- Bình luận