Can you explain why you need a custom field for the image ? if there is no special reason for that , you should use the_post_thumbnail() function that is built in wordpress and will not have you mess with custom fields.
You can read more here :
Display thumbnail from custom field
EDIT –
Well, if you insist on using it :
add_action('wp_insert_post', 'mk_set_default_custom_fields');
function mk_set_default_custom_fields($post_id)
{
if ( $_GET['post_type'] != 'post' ) {
$image1 = wp_get_attachment_image_src(get_post_thumbnail_id()) ;
update_post_meta($post_id, 'image', $image1[0],true);
}
return true;
}
Of course the feature image needs o be defined (or set a default) , and you can choose the sizes in the get_post_thumbnail() function.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Add image URL automatically to custom field?
- The the_post_thumbnail without srcset?
- Get the first image from post content (eg.: hotlinked images)
- Unexpected width and srcset attributes for the_post_thumbnail();
- Change loop order via form or link (jquery, not URL)
- How to set dimensions of the post thumbnails (featured images)
- Cannot get full thumbnail size using the_post_thumbnail
- Custom Field returning Numerical Value for Image rather than URL
- Reasons why all thumbnail sizes aren’t working
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- How To Pick Custom Size Of Uploaded Image In Theme Via the_post_thumbnail();?
- How to disable thumbnail filter for a specific template part or image size?
- How to make excerpt image be full size instead of thumbnail?
- How can I scale down the width of images in bulk that are embedded in posts throughout the site?
- theme directory fallback image outputs url and not the image
- Any disadvandages if I style the wordpress align classes without img and .wp-caption prefix
- I want to resize post featured image without cropping image. How?
- WP “optimizing” PNGs into thumbnails 5X larger than originals – FIX
- optimized PNGs 5X larger than originals
- How can I remove image taxonomy pages from my theme and from Google?
- Dynamic Image Links Depending on Excerpt/’Single Post’ View
- How to custom category template based on category?
- How to use multiple check-box values to work in a function and insert values in database
- Designing a custom archive.php inspired by the Autofocus theme
- ACF get_sub_field ALT TAG in the repeater doesn’t show
- How can I add a field for featured image on backend of a custom Taxonomy?
- WordPress Animation Adjustments
- How to hide featured images of all posts falling under the same category in wordpress?
- Post Featured Image Custom Sizing?
- Image cropping isn’t working correctly when using Offload Media
- Lightbox not showing image caption
- WordPress 5: including larger thumbnail image sizes in srcset than I have set
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- What is difference between add_theme_support and Theme Customization API?
- How to add an image to a theme page template in code?
- Created blank theme for REST API, featured image not appearing on admin side
- Is hand coding required at all?
- How to add the option to choose between sizes for featured image within post editor?
- Text View (Code View) in WordPress Customizer TinyMCE Editor
- how to edit woocommerce checkout page
- How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
- Responsive Images with art direction
- Customizer Image-Picker Preview Not Working
- What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- I want to change the author name
- Upload image without resizing but insert in post with resizing
- WordPress menu walker – Get parent item text inside end_lvl function
- How to dowload and edit content of a website
- Uncaught Reference error in Retina.js
- Make a custom field in admin post.php read only
- HTML TO WP Theme : Submenu goes down wp_nav_menu
- Can’t upload images on new theme
- Use a different catalog image than the featured image
- Images use & location, on new wordpress theme
- Add a customize control depending wich radio setting is checked
- image sizes – finding and removing
- Any way to permanently translate themes?
- WordPress Customizer Help with FontAwesome Icon
- Full width thumbnail
- Undefined index: custom_sidebars
- Adding a Class to an Getting From Post Content
- How to share posts (and plugins) between existing site and new, separate dev/test installation?
- How to prevent XSS attack in wordpress theme?
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Featured Image Module Randomly Disappears
- Best strategy for providing theme options using customizer
- Customizer API way function is_customize_preview() works only in main page?
- page.php is not called when I load a Page
- Create image with imagepng() (fails at header)
- How to add custom field option with menu?
- Single Featured Image Repeating
- Support Multiple featured images
- WordPress 3.5 + Foundation 5 not working on IE9
- How Does One Create a Global Variable Repository
- What hook to use for loading a custom class extension during Theme initialization?
- trying to figure out how to use more that one image upload in the same section in theme customizer
- How do I keep images in posts below a certain size without editing the post?
- Add custom field to existing meta box?
- Adding thumbnails for non-image attachments
- the_post_thumbnail fetches wrong image
- Theme Option’s Save Button is not working
- apply_filters to featured image
- Custom image size doesn’t work
- Retina ready for uploaded images which are cropped
- How to convert that page to a wordpress template? [closed]
- Show post thumbnail only if it exists using timthumb
- Not Found when using activity stream as front page with BuddyPress
- How do I change the tagline input to textarea?
- Add rel to all images in a post
- WordPress theme Modifications not showing up on live server
- Add image custom attribute [closed]
- Turning WordPress Into full-featured website?
- Display Page featured Image as well as Posts featured Image
- How to mark a image attachment as background image?
- Best practice to create required pages
- Permalinks problem with custom theme
- Add Field To All Pages
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?