Are you looking for a way to change the default options when inserting media into a post? While there’s probably a plugin for this, we have created a quick code snippet that you can use to set default attachment display settings, alignment, link to size in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function wps_attachment_display_settings() { update_option( 'image_default_align', 'left' ); update_option( 'image_default_link_type', 'none' ); update_option( 'image_default_size', 'large' ); } add_action( 'after_setup_theme', 'wps_attachment_display_settings' );
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 9 best WordPress real estate plugins and how to create a contact form in WordPress.
I am trying to make the sizes custom in attachment display and have put in the proper code for it, but I have elementor/astra theme and the attachment display settings appear to be missing from all images. Is there a way to get it to show?
I am having the same issue did you found any solution ?
worked for me, thank you 🙂
glad it helped 🙂
Even in 2019 this post is still relevant.. Thanks this worked for me
Glad it worked for you 🙂
Are there similar update_option settings for the Gallery menu? I don’t see anything in the reference but I’d love to change the defaults for the Attachment, Columns, and Size settings there.
What file should these be put in? wp_config.php? I followed the link to options reference and interestingly enough, they don’t say there either!
KingSky, sorry I was not clear, you can just add this to the functions.php