Display content in WordPress without images.
I myself once encountered such a problem when writing a block “Latest publications” on the main page of the site. The thing is,, that the block was small, and the display of images in this block could spoil the appearance of the main page of the site. I don't remember how I solved this problem, it was a long time ago but the decision, which was proposed by the author of the script Alexander Kolosovsky, I liked it and most importantly it works, code snippet was checked and approved by me ).
In the part of the site where it is necessary to display the content of the post without images, we write:
1 2 |
<?php add_filter('the_content','htm_image_content_filter',11); ?> <?php the_content(); ?> |
Then in the functions.php file we add a code snippet:
1 2 3 4 |
function htm_image_content_filter($content){ $content = preg_replace("/<img[^>]+\>/i", "", $content); return $content; } |
Thanks again to the author of the script Alexander Kolosovsky for the excellent code!
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.