X

How to Set Default Attachment Display Settings, Alignment, Link to, Size in WordPress

Snippets by IsItWP

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.

Comments   Leave a Reply

  1. 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?

    1. I am having the same issue did you found any solution ?

  2. worked for me, thank you 🙂

    1. glad it helped 🙂

  3. Even in 2019 this post is still relevant.. Thanks this worked for me

    1. Glad it worked for you 🙂

  4. 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.

  5. 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!

    1. KingSky, sorry I was not clear, you can just add this to the functions.php

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!