I created a plugin and I need to use add_image_size
in it.
I know how it works in the functions.php
file and for a theme, but how can I implement this in a plugin?
I want new images uploaded by WordPress users to be smaller for mobile screens by
add_image_size( 'wp_small', 60, 75, true ); // mobile
I read that you need to use init
or admin_init
but I don't know how to implement this.
I created a plugin and I need to use add_image_size
in it.
I know how it works in the functions.php
file and for a theme, but how can I implement this in a plugin?
I want new images uploaded by WordPress users to be smaller for mobile screens by
add_image_size( 'wp_small', 60, 75, true ); // mobile
I read that you need to use init
or admin_init
but I don't know how to implement this.
Just call this function in the init
action. This action is fired for both frontend and backend. So it should look like this:
add_action( 'init', 'wpse4378_add_new_image_size' );
function wpse4378_add_new_image_size() {
add_image_size( 'wp_small', 60, 75, true ); //mobile
}
It's better to call it in after_setup_theme
instead of init
action:
Codex says you should call add_image_size
in functions.php
so the closest action is after_setup_theme
. Then you have:
add_action( 'after_setup_theme', 'your_theme_setup' );
function your_theme_setup() {
add_image_size( 'wp_small', 60, 75, true ); //mobile
}
(Also explained in user contributed notes)