$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Get thumbnail url of custom meta image?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Get thumbnail url of custom meta image?

matteradmin8PV0评论

I have a line in my child theme as follows:

$bg_image = wp_get_attachment_url( get_post_meta(get_the_ID(), 'bg_image', true) );

It successfully provides me with the url of the image stored in the post meta, but what I would now like to do is specify a specific thumbnail size such as 'thumbnail' or 'medium'. The question was asked here but never answered.

Can anyone help?

I have a line in my child theme as follows:

$bg_image = wp_get_attachment_url( get_post_meta(get_the_ID(), 'bg_image', true) );

It successfully provides me with the url of the image stored in the post meta, but what I would now like to do is specify a specific thumbnail size such as 'thumbnail' or 'medium'. The question was asked here but never answered.

Can anyone help?

Share Improve this question asked Feb 4, 2019 at 8:38 RyanRyan 1233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You'll have to use different function for that.

wp_get_attachment_url returns a full URI for an attachment file and it doesn't know what type of attachment it is. It makes no sense to generate thumbnail for .zip od .txt files, so this function doesn't allow you to get thumbnail url.

On the other hand, wp_get_attachment_image_url knows that the file is an image, so you can tell it which size you want to get:

wp_get_attachment_image_url( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false )

As you can see, second param is the size:

$size (string|array) (Optional) Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order).

Default value: 'thumbnail'

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far