Be a Trainer! Share your knowledge.
Home » Wordpress » [WP Code] Add Featured image Automatic from 1st image From Post BY Minhajul

[WP Code] Add Featured image Automatic from 1st image From Post BY Minhajul

Now i m going to share a PHP CODE,

which will make Featured image automated.
in your WordPress Site.
Just Edit your WordPress theme ( Functions.php file )
And add this code before

function auto_featured_image() { global $post; if (!has_post_thumbnail($post->ID)) { $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); } } } } // Use it temporary to generate all featured images add_action('the_post', 'auto_featured_image'); // Used for new posts add_action('save_post', 'auto_featured_image'); add_action('draft_to_publish', 'auto_featured_image'); add_action('new_to_publish', 'auto_featured_image'); add_action('pending_to_publish', 'auto_featured_image'); add_action('future_to_publish', 'auto_featured_image');

সৌজন্যেঃ নিত্য নতুন টিপস পেতে
নিয়মিত

TrickzBD.GQভিজিট করবেন এবং
সবচেকম টাকায় সাইট তৈরী
করে টাকা ইনকাম করুন

স্বল্পমুল্যে ওয়াপসাইট বানিয়ে ঘরে বসেই
প্রতিদিন ৫০০ থেকে ৬০০ টাকা ইনকাম করতে
কল করুন। 01700535894

7 years ago (Dec 01, 2016)

About Author (71)

Firoj
contributor

???????

Trickbd Official Telegram

One response to “[WP Code] Add Featured image Automatic from 1st image From Post BY Minhajul”

Leave a Reply

Switch To Desktop Version