Support » Developing with WordPress » Get custom image size url for image send to editor

  • I have been trying to this right but it seems i just can’t.

    I want to get a custom image size for any image added to the editor. Here is my code:

    		add_filter( 'image_send_to_editor', 'wp_image_wrap_init', 10, 8 );
    		function wp_image_wrap_init( $html, $id, $caption, $title, $align, $url, $size, $alt )
    			$url = wp_get_attachment_image_src($attachment->ID, 'medium', false, false);
    			$html5 .= "<div id='attachment_$id' class='wp-caption $align'>";
    			$html5 .= "<img src='$url' alt='$alt' />";
    			if ( $caption ) {
    			$html5 .= "<div class='wp-caption-text afri-font'>(Photo: <strong>$caption</strong>)</p>";
    			$html5 .= "</div>";
    			return $html5;
    • This topic was modified 1 month, 1 week ago by  bcworkz.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    I’m not following how you are having trouble. The size being inserted is passed in $size. The value can be either a registered size like “large” or “my-custom-size”; or it could be an array of arbitrary dimensions like array(640, 480)

    If you want the dimensions for a different image size such as those of “medium”, use wp_get_attachment_metadata(). This returns an array of data. I don’t recall offhand the keys for the sizes. var_dump() the returned data to find out.

    You apparently struggled to properly format your code in your topic. Thanks for trying, we appreciate the effort. Probably the easiest is to highlight your code, then click the code button. You can demarcate with backticks, but the initial backtick must be the very first character on the line. Even intervening whitespace is not allowed. As you found, bb-code like [code] isn't entirely effective.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.