Skip to main content
Restructured question to me more understandible
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

Is there any way to display attachments Change attachment inside the post(embedded images) in custom sizethe_content using Filters?filters

I am in search of a snippet or function that will filter the Embeddedembedded images inside a post to a custom size I have defined in functions.php.

To make Clear Here is the scenario - In a blog Client does not care about the image sizes he insert inside the post usingHere is the scenario:

A client uploads and add media button, so some timesany image size into the_content(). Sometimes he will upload very large images, and if i use CSS to resize the image it will not always work correctly. So I think If isIs there a way to get the embedded images inand replacing them with a custom size that I have already defined to fit the layout dynamically using Filterthe_content filter.

Using the below code, I get all the attachments iI have inside the post, and can loop through it,

Now, Isis it possible to displaytake these image attachments, remove them from the_content, and replace them with a custom sized imagespost thumbnail I've specified in posts, even if uploaded Larger images inside editorfunctions.php.

EDIT:EDIT

summarize as - Search the content for any attachments coming through the_content()To make it more specific, and then display the Custom size versions of those images(those we defined inside functions.php)here is what I have in front end rather showing the original image uploaded.

TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODEmind, I am not a PHP geek, I know itthe code is a crapnot correct, but it is just a hint to what iI want,

What itthis should do, is it will return a specified image  (ie, themerpro_post_thumbthemerpro_post_thumb), that is exactly what I want, but the issue with the above code is, it will display only one image from the post, function returnsit should return an array, want to solve that,. The second issue is it will skip out the text inside the post  (iI mean paragraphs, etc...).

Is there any way to display attachments inside the post(embedded images) in custom size using Filters?

I am in search of a snippet or function that will filter the Embedded images inside a post to a custom size I have defined in functions.php.

To make Clear Here is the scenario - In a blog Client does not care about the image sizes he insert inside the post using add media button, so some times he will upload very large images and if i use CSS to resize image it will not always work correctly. So I think If is there a way to get the embedded images in a custom size that I have already defined to fit the layout dynamically using Filter.

Using the below code I get all the attachments i have inside the post, and can loop through it,

Now, Is it possible to display custom sized images in posts, even if uploaded Larger images inside editor.

EDIT:

summarize as - Search the content for any attachments coming through the_content(), and then display the Custom size versions of those images(those we defined inside functions.php) in front end rather showing the original image uploaded.

TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE, I am not a PHP geek, I know it is a crap, but just a hint to what i want,

What it do is it will return specified image(ie, themerpro_post_thumb), that is exactly I want, but the issue with the above code is, it will display only one image from the post, function returns an array, want to solve that, second issue is it will skip out the text inside the post(i mean paragraphs, etc...).

Change attachment inside the_content using filters

I am in search of a snippet or function that will filter the embedded images inside a post to a custom size I have defined in functions.php.

Here is the scenario:

A client uploads and add any image size into the_content(). Sometimes he will upload very large images, and if i use CSS to resize the image it will not always work correctly. Is there a way to get the embedded images and replacing them with a custom size that I have already defined to fit the layout dynamically using the_content filter.

Using the below code, I get all the attachments I have inside the post, and can loop through it,

Now, is it possible to take these image attachments, remove them from the_content, and replace them with a custom post thumbnail I've specified in functions.php.

EDIT

To make it more specific, here is what I have in mind, I am not a PHP geek, I know the code is not correct, but it is just a hint to what I want,

What this should do, is it will return a specified image  (ie, themerpro_post_thumb), that is exactly what I want, but the issue with the above code is, it will display only one image from the post, it should return an array. The second issue is it will skip out the text inside the post  (I mean paragraphs, etc...).

added 326 characters in body; edited title
Source Link
Salih K
  • 133
  • 1
  • 8

Is there aany way to display Embedded Imageattachments inside the post(embedded images) in custom size using Filters?

EDIT: TO

summarize as - Search the content for any attachments coming through the_content(), and then display the Custom size versions of those images(those we defined inside functions.php) in front end rather showing the original image uploaded.

TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE BY ME, I am not a PHP Master, sogeek, II know it is a crap, but just a hint to what i want,

  function myCustomSize(){
        global $post;
        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => null,
                            'post_status' => null,
                            'post_parent' => $post->ID,
                            'exclude'     => get_post_thumbnail_id()
                        );
                        $attachments = get_posts($args);
                        if ($attachments) {
                            foreach ($attachments as $attachment) {
                              return wp_get_attachment_image( $attachment->ID, 'themerpro_post_thumb' );
        
                            }
                        }
        
        }
        add_filter('the_content', 'myCustomSize');

Is there a way to display Embedded Image in custom size using Filters?

EDIT: TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE BY ME, I am not a PHP Master, so, I know it is a crap, but just a hint,

function myCustomSize(){
    global $post;
    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => null,
                        'post_status' => null,
                        'post_parent' => $post->ID,
                        'exclude'     => get_post_thumbnail_id()
                    );
                    $attachments = get_posts($args);
                    if ($attachments) {
                        foreach ($attachments as $attachment) {
                          return wp_get_attachment_image( $attachment->ID, 'themerpro_post_thumb' );
    
                        }
                    }
    
    }
    add_filter('the_content', 'myCustomSize');

Is there any way to display attachments inside the post(embedded images) in custom size using Filters?

EDIT:

summarize as - Search the content for any attachments coming through the_content(), and then display the Custom size versions of those images(those we defined inside functions.php) in front end rather showing the original image uploaded.

TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE, I am not a PHP geek, I know it is a crap, but just a hint to what i want,

  function myCustomSize(){
        global $post;
        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => null,
                            'post_status' => null,
                            'post_parent' => $post->ID,
                            'exclude'     => get_post_thumbnail_id()
                        );
                        $attachments = get_posts($args);
                        if ($attachments) {
                            foreach ($attachments as $attachment) {
                              return wp_get_attachment_image( $attachment->ID, 'themerpro_post_thumb' );
        
                            }
                        }
        
        }
        add_filter('the_content', 'myCustomSize');
added 1263 characters in body
Source Link
Salih K
  • 133
  • 1
  • 8

I am in search of a snippet or function that will filter the Embedded images inside a post to a custom size I have defined in functions.php.

To make Clear Here is the scenario - In a blog Client does not care about the image sizes he insert inside the post using add media button, so some times he will upload very large images and if i use CSS to resize image it will not always work correctly. So I think If is there a way to get the embedded images in a custom size that I have already defined to fit the layout dynamically using Filter.

Using the below code I get all the attachments i have inside the post, and can loop through it,

    $attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {
        .....
    }
}

Now, Is it possible to display custom sized images in posts, even if uploaded Larger images inside editor.

EDIT: TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE BY ME, I am not a PHP Master, so, I know it is a crap, but just a hint,

function myCustomSize(){
    global $post;
    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => null,
                        'post_status' => null,
                        'post_parent' => $post->ID,
                        'exclude'     => get_post_thumbnail_id()
                    );
                    $attachments = get_posts($args);
                    if ($attachments) {
                        foreach ($attachments as $attachment) {
                          return wp_get_attachment_image( $attachment->ID, 'themerpro_post_thumb' );
    
                        }
                    }
    
    }
    add_filter('the_content', 'myCustomSize');

What it do is it will return specified image(ie, themerpro_post_thumb), that is exactly I want, but the issue with the above code is, it will display only one image from the post, function returns an array, want to solve that, second issue is it will skip out the text inside the post(i mean paragraphs, etc...).

I am in search of a snippet or function that will filter the Embedded images inside a post to a custom size I have defined in functions.php.

To make Clear Here is the scenario - In a blog Client does not care about the image sizes he insert inside the post using add media button, so some times he will upload very large images and if i use CSS to resize image it will not always work correctly. So I think If is there a way to get the embedded images in a custom size that I have already defined to fit the layout dynamically using Filter.

Using the below code I get all the attachments i have inside the post, and can loop through it,

    $attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {
        .....
    }
}

Now, Is it possible to display custom sized images in posts, even if uploaded Larger images inside editor.

I am in search of a snippet or function that will filter the Embedded images inside a post to a custom size I have defined in functions.php.

To make Clear Here is the scenario - In a blog Client does not care about the image sizes he insert inside the post using add media button, so some times he will upload very large images and if i use CSS to resize image it will not always work correctly. So I think If is there a way to get the embedded images in a custom size that I have already defined to fit the layout dynamically using Filter.

Using the below code I get all the attachments i have inside the post, and can loop through it,

    $attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {
        .....
    }
}

Now, Is it possible to display custom sized images in posts, even if uploaded Larger images inside editor.

EDIT: TO MAKE IT MORE SPECIFIC HERE IS A SAMPLE CODE BY ME, I am not a PHP Master, so, I know it is a crap, but just a hint,

function myCustomSize(){
    global $post;
    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => null,
                        'post_status' => null,
                        'post_parent' => $post->ID,
                        'exclude'     => get_post_thumbnail_id()
                    );
                    $attachments = get_posts($args);
                    if ($attachments) {
                        foreach ($attachments as $attachment) {
                          return wp_get_attachment_image( $attachment->ID, 'themerpro_post_thumb' );
    
                        }
                    }
    
    }
    add_filter('the_content', 'myCustomSize');

What it do is it will return specified image(ie, themerpro_post_thumb), that is exactly I want, but the issue with the above code is, it will display only one image from the post, function returns an array, want to solve that, second issue is it will skip out the text inside the post(i mean paragraphs, etc...).

Source Link
Salih K
  • 133
  • 1
  • 8
Loading