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">

I would like to have images in full size, but I cannot find the right hook.

  • You can use the_content combined with is_attachment() function. Apr 15 '17 at 20:58
  • do you mean using if statements? Apr 21 '17 at 19:11

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

  • The question is about to change attachment image size from medium to original, but thanks anyway Apr 21 '17 at 19:10
  • @ClaudioKing ok did you solve it? Apr 21 '17 at 19:13
  • no, i left it on todo list Apr 21 '17 at 19:14
  • @ClaudioKing when I get off work I'll send you a fix for it. Question are you using the_content only for the image or there will be other content as well such as text? Apr 21 '17 at 19:18
  • I use the_content also for other single attachments, if you have a better solution tell me. Thank you Apr 21 '17 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.