Try this out. Your add_filter()’s second argument is a function, that will affect the current option via a return:
function theme_default_image_size() {
return 'custom-image-size-2';
}
add_filter( 'pre_option_image_default_size', 'theme_default_image_size' );
You could also look into the pre_update_option_{$option} filter, and update the value once, so you don’t need to run this filter every time (may save 0.01s, but it’s still saving!) 🙂
or good old update_option():
update_option( 'image_default_size', 'custom-image-size-2' );
Related Posts:
- Remove “Insert from URL” link in Media upload – WP 3.5
- Set media upload attachment link to none and hide it in WP v3.5
- Apply class to every paragraph that holds image?
- static variable loop not working in WordPress
- adding a filter to a shortcode?
- Hide old attachments from wp media library
- Change the footer text on the login page
- add_filter to post-gallery and remove all ‘s?
- How to overwrite youtube embed?
- Rewriting search and pagination base
- Check if page parent has certain template
- Change comments form title on a page by page basis
- Add custom image sizes to media uploader
- Remove class that has been added by parent theme
- How do I know what variables are passed in a filter/action and what their meaning is?
- Why do filters/actions require an argument count?
- How to use return in my custom function instead of echo
- Run a filter when a walker runs
- Handling Body class based on Template
- Get_avatar filter?
- Add a class to the anchor tag on HTML5 gallery
- add_action shortcut?
- How can I remove a function that has been added to wordpress with add_filter?
- How to control WordPress image metadata (using Imagick)?
- How do I add custom bulk actions to multiple custom post types?
- Add data attribute to each li in menu
- Removing “wpautop” (auto tags) only on certain pages?
- Print last modified date only on posts
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Unique icons next to each WordPress menu item
- Alter required message using comment form api
- Add item to top of menu using a filter in functions.php
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Filtering a function’ output for a new continued function
- Deleting Certain terms from appearing on the front end as links
- Content filter won’t work
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Create page template via functions.php?
- Add meta tags to a custom header
- How to have different site identity logos on each page on Astra Theme [closed]
- Custom query vars filters problem with pagination
- Get the name of menu item with wp_nav_menu
- How to add aria role and schema markup to custom walker container
- Must filter functions receive all arguments passed to them?
- Convert all uploaded PNG files to PNG-8 format
- Hide media for non logged in users
- User filter posts by year
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Apply function.php filter only if url not has /amp/
- Change lost password url to a mailto URL in WordPress
- Remove span tags from WooCommerce Downloads page
- How to bind each “the_content” elements to a custom variables
- Reload page with a different shortcode when a user selects from a dropdown
- WordPress Ajax filter: Create two loops for different output styles?
- Custom Bulk Actions handler not firing
- How to generate customized filtered output for the gallery
- How to remove title tag with this filter
- str_replace not preserving whitespace
- Woocommerce Price Text
- Limit Taxonomy Parents
- Display a post based on its metabox selection
- Search box background on a different page template
- Display a list of users with avatar filterable with alphabets
- AJAX: WordPress filters inside $html do not work as intended
- Assign new post author IF another user in custom field on post transition
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How to add different menu items on different menus?
- How to pass value to add_filter wpcf7_form_tag from another function?
- Add text below WooCommerce short description if metabox value is true
- Is there a hook that I can use when a fatal error occurs?
- Unable to logout correctly after wp-login file was modified
- Adding Author Filter to CPTs
- How can I display formatted content using the_content filter?
- Randomize Color Scheme Selection in Theme
- Extract and display user infromation on an automatically created page
- Custom Taxonomy Select Menu: Setting default option value?
- How to add author’s posts link (HTML + PHP) inside a function to output it
- Is it legal to redefine wp_password_change_notification in a mu plugin?
- How to Display a List of Child Pages For a Parent Page in WordPress
- Only load certain artists on this page
- Nav-Menu not showing up
- Show different website layout if no sidebar added
- Creating customized php files in theme folder
- writing an unique php function to be used on my website
- Child Theme’s Read More Text
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Unable to Call More than One Meta Box Output
- Hide a div when a custom field is empty
- Dynamically Generate Functions and Hooks
- Displaying Event within two given time frames
- How can I alter this code to accept a slug as well as an ID?
- Deactivate a plugin on wp version
- WordPress theme showing blank page
- Enqueueing a code block from an options framework
- Include a file that has a function in it
- Execute Jquery when a specific page in my plugin is loading
- Conditional On custom field plugin metabox