Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHARED: Wordpress Function To Get Featured Image From Post Youtube Video Or First Image
#1
Simple wordpress Function to get featured image from post youtube video or first image like tooxclusive and the likes


Have you ever wonder that there are some videos on tooxclusive, before you click on it, you'll see image but
after you do, you'll only met youtube video without any image in the post ?

I know many think the only way this is possible is by setting the image as featured image for the post instead of inserting it
through the post but i believe this might not be the situation, i believe the likes of tooxclusive, naijaloaded and others will want to do
everything possible to manage their hosting allocated files storage.
Moreover, it doesnt really make sense to set image as featured without inserting it into the post for users to see.

To make the long story short,
The most important aspect of this function is that, even if no image is present in the post,
but there is a youtube link either starting with youtube.com or youtu.be , so far it's a youtube url,
it'll set the featured image using the youtube video thumbnail and if there is any image in the post, it will make use of the image.

Please note: It's not neccessary for post to have youtube video for this to work, so far there is any other image in the post, even if there is no youtube video,
it'll set the image as featured image. So, this function is not just for post youtube thumbnail but also normal way to get featured image from the post content.


Put this in your theme function.php:





Put this where you want the featured image to show (Probably your theme index.php):








   If you have any question, feel free to ask below.

   Thanks
For Music Lyrics, Jokes, Stories & Lovely Text messages, visit Africu.com via  https://africu.com   today
#2
wow! this is one of the most sought after feature on WordPress! I once did this with a WordPress plugin but I've forgotten the name, nice share bro.
It takes so long to learn simplicity.
Reply
#3
@dealwap is like am getting something here.
Does it mean the written text is used to comand or program php?? Like    // If there's no image attached or inserted in the post, look for a YouTube video
   if (!$imageurl){
       // look for traditional youtube.com url from address bar
and so on.
I always see text with //*** and co and always think is of no use and atimes i deletes them ...please give me more tut on this
visit my site http://mobVibe.ga for music downloads and more...
Reply
#4
@Meeky if you study html well, you will notice that comments lines in html are denoted with <!--Your text --> likewise in php too you can also put a comment btw your scripts using // for single comment lines or /* your text */ for multi comment lines that wont really interfere in your codes but they are very useful for keeping track of our codes and also makes debugging easier or if you are making an Open Source application you need to add comment lines for the people that will use your software be able to read through your code lines and notice or understand what each functions stands for and how each syntax are been mingled with themselves.
It takes so long to learn simplicity.
Reply
#5
(12-30-2016, 07:48 PM)Dealwap Wrote:
@Meeky if you study html well, you will notice that comments lines in html are denoted with <!--Your text --> likewise in php too you can also put a comment btw your scripts using // for single comment lines or /* your text */ for multi comment lines that wont really interfere in your codes but they are very useful for keeping track of our codes and also makes debugging easier or if you are making an Open Source application you need to add comment lines for the people that will use your software be able to read through your code lines and notice or understand what each functions stands for and how each syntax are been mingled with themselves.


thanks but no explanation will do
visit my site http://mobVibe.ga for music downloads and more...
Reply
#6
what of the written text (// If
there's no image attached or inserted in
the post, look for a YouTube video) are der part of the code ?? @dealwap
visit my site http://mobVibe.ga for music downloads and more...
Reply
#7
(12-30-2016, 08:07 PM)meeky Wrote:
what of the written text (// If
there's no image attached or inserted in
the post, look for a YouTube video) are der part of the code ?? @dealwap


They are instructions to guide you on how to use the code.
It takes so long to learn simplicity.
Reply
#8
(12-30-2016, 04:18 PM)Dealwap Wrote:
wow! this is one of the most sought after feature on WordPress! I once did this with a WordPress plugin but I've forgotten the name, nice share bro.



Yea it's true, there are plugins to do this but I believe every programmer will prefer using code if possible to plugin since there is possibility of too much plugins slowing down your website
For Music Lyrics, Jokes, Stories & Lovely Text messages, visit Africu.com via  https://africu.com   today
Reply
#9
(12-30-2016, 09:43 PM)Horlami Wrote:
Yea it's true, there are plugins to do this but I believe every programmer will prefer using code if possible to plugin since there is possibility of too much plugins slowing down your website


Plugins can't really slow down your website if used in the right way but I'll always suggest using a code for it anyway the plugin is just there for pepe that don't want to go through much customisation.
It takes so long to learn simplicity.
Reply
#10
(12-30-2016, 10:10 PM)Dealwap Wrote:
Plugins can't really slow down your website if used in the right way but I'll always suggest using a code for it anyway the plugin is just there for pepe that don't want to go through much customisation.


Yea, that's true, but it's just believed that too much of plugin can slow down a website since it need to load all the plugin header details, for example, if you source code a WordPress website, you'll notice most plugins have it different js files and other things which are added to the header content, and even under normal circumstances, we are advised to import all css files for example in just one css instead of linking to them all one by one to increase the site speed and SEO
For Music Lyrics, Jokes, Stories & Lovely Text messages, visit Africu.com via  https://africu.com   today
Reply
#11
@Horlami, exactly!
It takes so long to learn simplicity.
Reply
#12
Wow I love this post can this php script be use on a magazine theme ?
I am a proud member of NIgerian Coders Team
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  SHARED: 5 Best Wordpress Music Themes Free Download plus1nigeria 1 239 Today, 08:18 AM
Last Post: juilia
  SHARED: New "naijaloaded" Wordpress Theme [new Version] 46hype 13 226 Yesterday, 02:26 PM
Last Post: Hackinubee
Tongue SHARED: Latest 9jakolong Wordpress Theme Shared Deelino 10 152 Yesterday, 01:44 AM
Last Post: Phanteez
  HELP: How To Fix Distorted Image Thumbnails Micassa 10 154 06-18-2018, 01:23 PM
Last Post: Micassa
  HELP: Okhype.com Current Wordpress Theme Needed Please! KvnGfeLix 8 240 06-18-2018, 12:19 AM
Last Post: Hackinubee
  Mp3 Tag Editor For Your Wordpress Site (uploads To Your Database) platvipez 97 13,585 06-15-2018, 11:44 AM
Last Post: Joepraiz111
  SHARED: Newsmag Lite: Responsible Wordpress Theme Free Download Bigga5 2 164 06-15-2018, 11:43 AM
Last Post: Joepraiz111
  SHARED: Waploaded Wordpress Theme Free Download 46hype 0 69 06-15-2018, 08:54 AM
Last Post: 46hype
  HELP: I Need help to Use Two Themes On One Wordpress Blog Dhray 9 147 06-14-2018, 07:55 PM
Last Post: DennyS
Music Help On My Wordpress Music Blog Tunamiredex 4 134 06-05-2018, 05:30 PM
Last Post: lanrefaund



Users browsing this thread: 1 Guest(s)

About Nigeria's Creative Talents

Nigeria's Creative Talents is an online community where every creative Nigerians can share ideas with themselves.

For any more information, please use our contact form.

              User Links

              Advertise