Generate left on all images in messages – is there a hook?

Generate left on all images in messages – is there a hook?

2 minutes, 5 seconds Read

I worked on a similar problem, so found a possible solution.

The problem is the ‘inline’ images, in contrast to images that are attachments (such as a gallery), is that there is no filter for it the_content() That deals specifically with the images tag. (At least I haven’t found it yet.)

So you have to use some regex to search the_content() Before getting the image and every image in an array, you can go through the image array as you need.

I found this code here: https://gist.github.com/jlord/3680879 . I didn’t test it, but it can start you:

 // get the content from the post
  $posttext = $post->post_content;
  // next line added to process any shortcodes in the content string
  $posttext = do_shortcode($posttext);
  // make a variable for the string you're looking to find in all of the content
  $regex = '~]*\ />~';
  // find the first things inside of the second thing and put them inside of the third thing
  preg_match_all($regex, $posttext, $images);
  // redefine posttext as itself minus all the things you found 
  $posttext = preg_replace($regex, '', $posttext);

  // now posttext has no images, and $images is an array of image tags
  // have fun, o lord of jellies ?> 




You would place this code in a template in the loop. Then use that template for the post output.

I would be interested if this helps. It can save you on the Googles for a few hours, that’s how I found it.

Added

Since the $posttext = $post->post_content; does not use the_content() (which also processes short codes), then short codes may not be processed in the postal content. In particular the

Short code is not processed. I suspect that other short codes are not being processed either.

So I added an extra rule to the code above:

$posttext = do_shortcode($posttext);

To have short codes processed in the contentstring.

Added

With the above code you cannot necessarily connect the output of gallery images. So I have found this code here, which can be used as a starting point: how you can get post -attachments in Gallery Post format template

if ( get_post_gallery() ) :
        $gallery = get_post_gallery( get_the_ID(), false );

        /* Loop through all the image and output them one by one */
        foreach( $gallery['src'] as $src ) : ?>
          
  • Note that all the above code features are not an end-to-end solution. But they can be useful to put together a solution that meets your needs.

    #Generate #left #images #messages #hook

    Similar Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *