0

Is it possible to set default options for inserting image into article. I want every image to link to full image and be right aligned. Setting this manually every time is annoying and unproductive.

Can I do this with some hook in my functions file?

  • Have you tried anything so far to right align the image, for instance, the img_caption_shortcode filter? Does this need to work in MCE editor and on the live website? – prosti Jan 5 '17 at 17:39
2

You can do this in two ways. If you want to keep it theme specific, edit your functions.php file with this code:

add_action( 'after_setup_theme', 'my_new_default_image_settings' );

function my_new_default_image_settings() {
    update_option( 'image_default_align', 'right' );
    update_option( 'image_default_link_type', 'file' );
}

The other way to do it is more general, but also more rigid:

  1. Go to YOURSITE.COM/wp-admin/options.php
  2. Find the image_default_link_type field.
  3. Type in file.
  4. Find the image_default_align field.
  5. Type in right.
  6. Scroll to tho bottom and hit Save.

Some helpful references:

  • image_default_link_type has either file or none as its available options. Unfortunately, it doesn't appear that you can set it to a custom URL or the attachment page by default. I'm not really sure what you mean by "link to full image" but hopefully that works for you. – Khaled Allen Jan 5 '17 at 18:49
  • 1
    great solution, it works only for the new images, just as needed and it works from the MCE editor. – prosti Jan 5 '17 at 19:22
0
add_action( 'admin_init', 'default_image_settings_options' );
function default_image_settings_options() {
    update_option( 'image_default_align', 'center' );
    update_option( 'image_default_link_type', 'file' );
}
  • Some explanation why this is better/different from the accepted answer would be nice. – cjbj Aug 21 '18 at 14:16
  • This runs an UPDATE on every page load. Not a great idea. – fuxia Aug 21 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.