WordPress : Set first image of the content as featured image

If you’ve migrated your blog from another platform to WordPress or changed your theme, you may be wondering why some post thumbnails aren’t being displayed anymore. This could be because the featured image for that particular blog-post isn’t set. If you’ve very few posts, you can do it by editing those posts and set a featured image manually, but what if you’ve hundreds or thousands of blog-posts?

In that case, rather than to edit each post and set a featured image manually, you can use the following code snippet. This snippet will set the first embedded image from the content as the featured image – only if there is no featured image been set. For any external images, it also creates a media file and stores it in a WordPress Media Library. This is very useful to generate and set featured images in bulk.

Add the below code snippet in the functions.php file of your active WordPress theme, and load All Posts ( {YOUR-DOMAIN}/wp-admin/edit.php ) page or any single post page, and it will do the magic.

Once you verify that all the featured images been set properly, you can remove the above code snippet from the functions.php.

* Photo credit: Guilherme Vasconcelos on Unsplash

Allow vendors to upload only specific file types in EDD Frontend Submissions

Easy Digital Downloads - Front-End Submissions - Allow only specific mime types upload

Frontend Submissions is an add-on that turns Easy Digital Downloads powered WordPress website into a complete multi-vendor marketplace. Based on your marketplace, you may need to restrict the certain file type uploads or allow specific file types upload only for your vendors.

I am sharing a code snippet that I just have written, and implemented on one of my client’s EDD FES website. Inserting it into WordPress theme’s functions.php will restrict vendors to upload any other file types and allow only zip file type upload.

Have you any better solutions? I would love to read your comments.

Customise WordPress Dashboard for Clients

To keep your clients from risky places or to restrict access to specific pages from the clients, you can customise your WordPress dashboard by adding the below code in your theme’s functions.php. This code allows you to hide parts of the WordPress dashboard menu.

You need to uncomment the line ( remove // ) for the page that you want to hide/remove from the WordPress menu.

Be aware that this only hides the menu items from the dashboard and clients can still theoretically access these menus with a direct link (if they know).