You can’t define a hook callback function inside another function.
You’ve defined my_custom_sizes() inside setup(), which means that my_custom_sizes() cannot be called outside of the scope of setup(). This is a problem because the hook, image_size_names_choose, is not run inside your setup() function. You need to define your callback in the global scope:
function setup()
{
add_image_size( 'banner-ad', 655, 100, true );
add_image_size( 'banner-rectangle', 655, 250, true );
}
add_action('after_setup_theme', __NAMESPACE__ . '\\setup');
function my_custom_sizes( $sizes )
{
return array_merge( $sizes, array(
'banner-ad' => __( 'Banner Ad' ),
'banner-rectangle' => __( 'Banner Rectangle' ),
) );
}
add_filter( 'image_size_names_choose', __NAMESPACE__ . '\\my_custom_sizes' );
Related Posts:
- Enforcing password complexity
- Can i check if user is doing any ajax request?
- Hooking new functions to actions + passing parameters
- Why do filters/actions require an argument count?
- How to access function from outside of a class within this class in WP plugin?
- How to use return in my custom function instead of echo
- Adding Default Settings to Theme My Login plugin
- add_action shortcut?
- Modify custom field input data before creating a new post
- jQuery code not working when included in functions.php
- Override a function defined in wp-includes/comment-template.php
- Nested “do” and “add” Actions is possible?
- WordPress redirect redirecting too many times or not at all
- How to pass hook variable to function?
- remove_action from parent theme using child theme functions.php
- Hook into all password resets in WordPress and get password before hashing?
- remove_action() not working in page template – Genesis
- Unable to pass arguments to function used in add_action
- WordPress HTML Helper
- Highlight posts currently being edited on multiple editor site?
- Why a class property becomes empty?
- Is there a hook that I can use when a fatal error occurs?
- Execute wp_after_insert_post after the permalink is customized
- PHP code in page template vs functions
- Apply class to every paragraph that holds image?
- username_exists() function can’t be access without logging in
- How to preserve PHP modifications while upgrading WordPress?
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- Delete post revisions on post publish
- Best way of adding CSS which can be manipulated by the user via theme option panels?
- How to Append to the_excerpt() Function
- How do I list the_tags() into HTML data-attribute
- WordPress if (is_page) translation on certain page
- Check if term object is in array
- Highlight Current Tag in wp_tag_cloud
- Getting rid of role=”navigation” in the Home Page Pagination
- syntax issue on php 7.4
- How to remove the excerpt in the Dzonia Lite theme
- Get first URL from post content
- Setting custom canonical urls
- Trigger popup in a php if/else statement
- Setting a cookie upon specific URL visit
- get post based on category chosen in drop down – The ajax method
- How to stop or remove an action being called inside a function of an extended class
- How to output a PHP file values by shortcode?
- Set the background to a default image if there isn’t a specified “featured image”
- Logged in user ID as post ID
- WordPress Access allowed to fewer pages till user logs in
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- different id for same element visual composer [closed]
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Query Pages and post excerpts dynamically
- Is it possible to return content, and then also continue to do other things?
- How to remove ?p= from wordpress short links
- Need php code’s output to display underneath a Divi Module
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to make function appear in sentence?
- How to define a variable already defined in a plugin function?
- woocommerce specific quantities for product
- How to use mysql LIKE with wpdb?
- woocommerce related product title length
- Custom query vars filters problem with pagination
- Woocommerce custom Plugin in wordpress [closed]
- Query for user roles
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Displaying Event within two given time frames
- How to call custom function outside from the admin page?
- Is there a way to create a “copy post” link?
- Use of antispambot with $curauth->email
- Restrict post to current user in postmeta
- posts_per_page displays only 2 posts instead of 4 posts
- Adding product permalink on admin order page throwing error
- Before & After Content – After Content directly below Before Content when using require_once
- Taxonomy Child Term, Counter is staying on 0
- Access to “My Site” is missing from the admin bar
- How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page
- How to call WordPress PHP file using external js file
- Using get_theme_mod with checkbox to display content
- use system script advertising in wordpress multisite
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Help with my first Metabox helper class
- Pagenav Not appearing on custom Template
- ISOTOPE – Missing/Invalid Arguement Get Terms
- How to add custom checkout field in user details mail template
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Adding multiple conditional tags in a function?
- Understanding responsive imagery
- How to get meta box labels?
- How do I stylize selected comments?
- Too few arguments – wp_login action
- “acf/load_field” Critical error upon saving/updating WooCommerce products [closed]
- How do I make a shortcode to display Dokan seller badge list?
- Function extension
- Developing a “fallback” for empty wp_query results based on post dates
- How can I process a form submission from an HTTP POST request?