I am building a theme and I use single.php
also for attachments.
The problem is that WordPress print automatically the images with the_content()
in this way:
<p class="attachment">
<a href="http://www.example.com/wp-content/uploads/2013/09/dsc20040724_152504_532.jpg">
<img src="http://www.example.com/wp-content/uploads/2013/09/dsc20040724_152504_532-300x225.jpg" class="attachment-medium size-medium" alt="" srcset="http://www.example.com/wp-content/uploads/2013/09/dsc20040724_152504_532-300x225.jpg 300w, http://www.example.com/wp-content/uploads/2013/09/dsc20040724_152504_532.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" width="300" height="225">
</a>
</p>
I would like to have images in full size, but I cannot find the right hook.
1 Answer
you can try this
function filter_ptags_on_images($content) {
$content = preg_replace('/\s*()?\s*()\s*()?\s*/iU', '\1\2\3', $content);
return preg_replace('/
\s*(*.)\s*/iU', '\1', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
this also has been solved here
remove p tags from images