[wp-trac] [WordPress Trac] #51908: add_image_size not working with custom plugin code
WordPress Trac
noreply at wordpress.org
Wed Dec 2 12:30:10 UTC 2020
#51908: add_image_size not working with custom plugin code
-------------------------------+------------------------------
Reporter: arpitgshah | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: docs
-------------------------------+------------------------------
Comment (by azaozz):
Replying to [comment:3 arpitgshah]:
> @audrasjb here we have some sample code,
>
> {{{#!php
> <?php
> add_action( 'init', 'custom_post_size', 0 );
>
> function custom_post_size() {
> add_image_size( 'custom-size', 220, 180, true );
> the_post_thumbnail( 'custom-size' );
> }
> }}}
Hmmm, looking at this example, what is the purpose of
`the_post_thumbnail()` call there? This function is used to display an
image (usually) on the front-end, see
https://developer.wordpress.org/reference/functions/the_post_thumbnail/.
Calling it on `init` is "wrong" :)
> It's also not working with the code as well. We also need to find
something alternative.
As far as I understand the bug here is that when calling
`add_image_size()` from a theme's functions.php, it has to be done on the
`after_setup_theme` action hook. That needs to be added to the docblock
there.
Is there another problem/bug?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51908#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list