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?
- How to modify an image block in Gutenberg WordPress 5?
- How can I set image sizes and still have responsive images using the srcset attribute?
- Add default Backgrounds
- Best practices – Should I create a child theme vs. customizing a framework theme? (such as HTML5 reset)
- How to disable 3.1 “Admin Bar” via script for the admin user?
- add_image_size is scaling, even though crop is set to true
- How the WordPress sidebar works
- Should we localize custom-made themes / plugins?
- Extend walker – navigation, adding data attribute to a tag
- How can I remove the Static Front Page option from the Customizer
- Replace Home with image link inside custom header menu
- How can i customize the comment list
- Setup A Default Featured Image
- How to handle theme customization and sass variables
- wp_enqueue_scripts not called on search page?
- wp_head() not inserting the default stylesheet style.css
- First completely customized theme, where should I start?
- Theme Customizer not loading
- Best practices: Custom theme sidebar menu – hardcode or widget?
- Best approach to create sites with Modular Content? [closed]
- Customizer API and add_panel(). Panel doesn’t show
- How to correctly add JQuery in a WP theme?
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- A mystery 300px image size
- Removing non native customizer settings from a child theme
- How to reorganize the items returned by wp_list_comments()?
- which is the best way to customize nav-menu-template.php?
- Featured Images are not able to be set
- How to make a local cache of mshots images
- How to add a button which saves the post then executes a function
- Limitations when modifying wp_title with a filter
- How to edit theme functions file to modify pagination?
- image url relative path not working in css file
- Disabling Customizer Selective Refresh shortcut icons for selected controls
- Sort wp_query by sum of two meta fields
- Q: How to pull data from custom table to populate zustomizer setting/control select options
- What’s the best practice way of handling custom fields in different post formats?
- Using My Own Classes On Wp Unit Tests
- Reactor Theme: Prevent Post Thumb on Post
- Inserting images in multiple posts native gallery
- Can I get the ID of an inserted / linked image?
- What is the meaning of WordPress’s recommended css classes and where are they applied?
- Integrate WooCommerce theme with a WordPress theme [closed]
- How do you use WordPress for a website that’s not in a blog format?
- Replace site title with logo when logo is uploaded in customizer using
- the_post_thumbnail() get the URL to the “medium” sized image
- Templates without a loop, best practice?
- searchform.php doesn’t work properly
- Theme logo metadata into template file
- Customizer: get_preview_url() inside customize_save_after hook
- How to add custom meta box when you have a custom page template file
- Custom field as featured image caption
- How to call a widget in a loop at a specific iteration value?
- Full width featured thumbnail
- Right procedure when you develop a WP Website for a client
- New to WordPress – Read the Codex, Other Docs; Still Confused
- How to add custom page elements to the WYSIWYG editor?
- How to use shortcode inside of shortcode in theme
- How can I get the featured image or the first image for a post/page and display it as a banner?
- How to add cropped custom header image?
- My contact form – I’ve changed the source code but the changes are not being applied
- Selectively hiding or allowing thumbnails of featured images on front page
- How to custom category template based on category?
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
- What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]
- Add a customize control depending wich radio setting is checked
- 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?
- Featured Image Module Randomly Disappears
- How to add custom field option with menu?
- WordPress 3.5 + Foundation 5 not working on IE9
- How do I keep images in posts below a certain size without editing the post?
- Theme Option’s Save Button is not working
- Show post thumbnail only if it exists using timthumb
- Best practice to create required pages
- Permalinks problem with custom theme
- How can I add a single image from a gallery into the page header?
- How to split the site’s layout without damaging this layout? [closed]
- Isotope overlapping .items because of featured images – HELP! [closed]
- Multiple content areas with Gutenberg – Transparent areas mid content