Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active January 7, 2021 11:53
Show Gist options
  • Save mklasen/c74c63062023e18369866223d0af643c to your computer and use it in GitHub Desktop.
Save mklasen/c74c63062023e18369866223d0af643c to your computer and use it in GitHub Desktop.
WordPress: Add image size to block editor settings (ex: Media & Text block)
<?php
class Main {
public function __construct() {
$this->init();
}
public function init() {
add_action( 'after_setup_theme', array( $this, 'add_image_sizes' ) );
add_filter( 'image_size_names_choose', array( $this, 'show_image_sizes' ) );
}
public function add_image_sizes() {
add_image_size( 'custom-logo', 220, 180, true );
}
public function show_image_sizes() {
$sizes['custom-logo'] = __( 'Custom logo' );
return $sizes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment