blog-posting-from-microsoft-word

A1WEBSITEPRO QuestionsCategory: WordPressblog-posting-from-microsoft-word
ABdul asked 4 years ago

Posting blog from microsoft word to wordpress  I want to know how to set featured image directly from MS word  

blog-posting-from-microsoft-word was last modified: April 10th, 2020 by ABdul
1 Answers
Best Answer
Maximus Mccullough Staff answered 4 years ago

So one way you can handle this issue is by making the very first image the featured image by putting the following code in your functions.php file on your child theme.

function wpsites_auto_set_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
}
add_action('the_post', 'wpsites_auto_set_featured_image');

Answer for blog-posting-from-microsoft-word was last modified: March 19th, 2023 by Maximus Mccullough