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
- Disable RSS /feed/ endpoints on posts without disabling RSS overall
- Call to undefined function get_userdata() in plugin
- Echo string and function?
- add_action taking an array with the 2nd argument?
- How can I make an object available through the entire site?
- WordPress admin-ajax.php
- 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?
- How do I modify the custom footer text and get theme version number to show in wordpress admin?
- How to use html inside a functions.php code?
- Sidebar not appearing in footer, but it appears everywhere else!
- linking stylesheets and scripts with functions.php
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Remove item in Checkout
- How can I hook into the wp_mail function used by BackWPup?
- How to get current post category details inside “loop”?
- List post by title length
- how to enqueque code in a php file from functions.php
- Only load certain artists on this page
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Get the alt text of the image in a array
- Convert all uploaded PNG files to PNG-8 format
- Make table disappear when fields are left blank?
- Uses for function: wp_update_user
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Woocommerce order status payment
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Unzip file in functions.php, and add it to cron
- Add Block Before Entry Title Using PHP
- WordPress Post Block Element not properly parsed with the_content filter
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- Dynamically populate parameter in Gravity Forms using PHP
- Store ajax data in PHP variable
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- How to output the taxonomies that are assigned to each custom post?
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- How can i create a function tag in my plugin
- Exclude category from function – PHP
- How to escape echo for input tag?
- Including user data in “new user notification email”
- Hide a specific category title from displaying on site
- How do I remove an action hook inside a class that is called by another class?
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- Refresh page after login with litespeed cache
- Return newly created category by code
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Woocommerce Add custom “Add to cart button” in single page with tags
- Populate Posts based on category selected using AJAX that means without page refresh
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- 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?
- Can’t get_users info by using json_encode
- Add two or multiple functions in WordPress Post or Page
- Submit to itself don’t work
- What is wrong in this code?
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- Page returning ID from array, how to return the correct values for post in acf wordpress
- WordPress get_post_meta issue
- Woocommerce Price Text
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- Show custom default avatar instead of gravatar
- Permission error on plugin save
- Removing all my hardcoded URLs with get_site_url()
- WordPress 2014 Theme – Featured Content with multiple tags?
- Display default WordPress login/registration form into a modal window
- Highlight main menu when on specific posts or pages
- 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
- ajax form function error
- Display custom meta box in my template file
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to display the date under the post title?
- Simple Probléme in wordpress