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?
- wp_set_object_terms and arrays
- How to get the original price of the product in woocommerce?
- How to use WordPress (PHP) functions in AngularJS partials files?
- Can I write ‘RewriteCond’ using ‘functions.php’?
- How to Remove a Filter from the Admin List Table?
- How to add 2 posts under another post? Formatting should be intact
- Get widget settings function?
- enqueue multiple Google fonts with multiple weights and styles (italic)
- What is the fastest way to load PHP functions that are only used in one theme template?
- Adding tawk.to code just before body tag on functions.php file
- WSoD being caused by this piece of code
- ACF: how do I get the fields and its values of a specific group?
- How to complete two other input fields, completed the first
- Trying to place a custom field after the total section in the checkout page in woocommerce
- Get page that displays all children of taxonomy parent
- Function to capture a value and store it in a variable
- Adding a widget function into the php theme file
- My new button is in the wrong place
- Checking array against author id in loop
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- Call to undefined method – Download Monitor
- How do I link a button I created in theme customizer to a function?
- Security for data obtained from the database
- Make Current/Active Page Number a Link (WP_LINK_PAGES)
- How to make modifications only to certain elements of an HTML string on the server-side?
- Custom Pagination is Broken
- Sidebar not appearing in footer, but it appears everywhere else!
- Co-Authors Plus: How do I get all authors with a query?
- Why i can’t get custom fields value or post ID via Ajax?
- List post by title length
- How to reference PHP in Javascript
- Fallback image URL if no featured image exists via a shortcode function
- Deactivate a plugin on wp version
- making php value numeric
- the_post_thumbnail issues
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- Uses for function: wp_update_user
- WP insert post Redirect after function has executed
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- How to Send Pingbacks for all Posts in WordPress?
- HTML comment cause issue in functions.php script root
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Exclude category from function – PHP
- Hide a specific category title from displaying on site
- WordPress Ajax filter: Create two loops for different output styles?
- Handling form actions in WordPress
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Why should I need to add init action to include PHP file to WordPress Plugin?
- How to call a function from functions.php with ajax?
- Set user status to absent on WordPress
- Shortcode’s output to use as other shortcode’s parameter
- Displaying POST content with HTML tags and all
- How to hook into the subscriber /wp-admin/index.php page?
- PHP script to redirect traffic based on website accessed
- How to remove title tag with this filter
- Why transition_post_type hook is called twice for the same post?
- Showing wordpress latest post thumbnails in slider with auto increment
- Add two or multiple functions in WordPress Post or Page
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- Limit Taxonomy Parents
- List sibling pages widget, exclude current page
- Permission error on plugin save
- Display default WordPress login/registration form into a modal window
- How to add button to top of theme customizer?
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- Pull GET parameter from URL in functions.php
- Adding Gravity Form With if(is_page) Is Not Working
- Send foreach $_post method to contact form 7 [closed]
- Options.php loop won’t show!
- Understanding responsive imagery
- How to get meta box labels?
- How do I stylize selected comments?