Create A Wordpress Widget - Part 1
Key Takeaways
This video demonstrates how to create a WordPress widget, specifically a Facebook likebox widget, using PHP and JavaScript. It covers the basics of WordPress plugin development, including creating a plugin folder, adding a comment block, and registering the widget.
Full Transcript
hey guys in this minseries we're going to be building a WordPress widget all right and a WordPress widget is basically a plug-in uh it's just a certain kind of plugin you can log in into your WordPress admin area and go to widgets and then you can pretty much drag them to uh whatever position your template allows all right and what we're going to be building is basically a a Facebook likebox widget um so you can get a like box if you go to this URL all right so normally the user would need to uh enter their page URL uh set up some parameters like the width the height the color what they want to display and then they would have to get the code and they would have to get this JavaScript SDK and include that in their site and then they would have to find somewhere to to embed this HTML um and for someone that's not a developer and doesn't know much about um HTML or JavaScript uh can be kind of a pain so uh this widget will just will be able to install it in a WordPress site very easily um basically just upload it and then the user can go to the back end and go to the widget parameters and they'll be able to edit this stuff there okay instead of having to come here and then generate the code and all that all right so uh that's what we'll be building and if you're serious about learning how to build WordPress plugins and widgets um I suggest going to this URL okay this is the widgets API and this actually has a lot of the code that we're going to use um and there's a bunch of other information as well um I'd also suggest going to the plug-in API page as well all right so this is our site um actually let me reload that's not supposed to be there so it's just a basic Al a default WordPress installation uh this is version 3.91 but I do have the I think it's the 2012 template enabled um just because it's easier to see the sidebar and all that all right so with that said what we're going to do is open up I'm using notepad++ all right and I'm in my let me go to the root directory okay so this is the root directory of my WordPress site okay so what we're going to do is we need to go to the wp content folder and then the plugins folder and then we want to create a new folder and I'm going to call this likebox okay and then in that folder we're going to create a couple files all right so the first one is going to be just called likebox PHP and then we're going to create another file I'm going to call this one class. likebox PHP okay so this will be our main file um and then we'll include this which will be the like bux it'll be the widget class um and that's where most of our coding will be okay uh and I'm also going to create a new folder called JS because um we need to include our JavaScript SDK so inside there I will create another file and I'm just going to call this actually I'll call it um like box. JS okay so these are our three main files all right and we'll start with the the main file which is basically the entry point for the widget so the first thing you need to do when building a plugin is you need to include a comment block which basically um shows your WordPress that you have a plugin and it displays the name and also um you need to have it so that it'll pop up in the back end all right so we want it to show if we go to plugins all right we want it to show here so we can actually activate it okay and let me just get that code for you okay plug-in API if we scroll down where is it maybe this isn't the right okay writing a plugin this link here here we go all right so here we have the I guess called file headers okay so it's just this comment Block in PHP so I'm going to copy that and paste it and we're just going to change some some things here the plug-in name is going to be likebox plug-in URI um I'm just going to say Cod skillet.com description we'll just say uh simple plugin to show Facebook like box I believe the only field that's required here is the plug-in name I don't think you need any all this uh it's just good to have though um just for metadata version will be 1.0 author feel free to put your own name okay URI we'll say Cod skillet.com and then license we'll say gpl2 that's fine all right so this is actually all we need for it to show up in WordPress so if you save that and then go ahead to the back end and and reload this plug-in area now you can see we have our likebox plugin okay it has the description the version the author it goes to the to the author's site so very easy to actually get it to show up here all right so um let's see I'm not going to activate it yet what I want to do now is I want to get it so we can include our Javascript file so we're going to create a function okay and this is going to be called addore scripts all right and then in this function we're going to call a JavaScript function called WQ uh I'm sorry WP um what is it n qu e u e scripts all right and we can actually look this up all right so basically um it has a few parameters okay uh that actually this one here is for CSS same thing but except style all right and here's ours wpnq script all right and the parameters uh let's see the parameters the first one here my J this can basically be anything it just uh basically is a a context reference um the next one is going to be the actual URL to the Javascript file and the false I can't remember exactly what that is um doesn't look like it gives us a description of the parameters example all right well basically we're just going to use false for that third parameter uh so the first parameter I'm just going to put you want to make sure you have quotes and we'll say likebox scripts okay the next one is going to be a URL or uh a link to our Javascript file and in WordPress we can actually use this plugins uncore URL function and that will get us to our actual plugins folder all right so from the plugins folder we want to concatenate on slash likebox and then sljs slash likebox DJs and that'll bring us to our JavaScript file and um let's just put in false for the third parameter all right so that is our ad scripts function right now it's not going to do anything it's just a declaration so we have to tell WordPress when to run it so we're going to use this add action hook all right so what we're going to say is the first parameter is going to be this WP NQ script I'm sorry this first one should be script okay singular and then this here is scripts all right this is the actual hook so um oops the next parameter we just want to put in the name of the function that we created which is ADD scripts okay so that should add that now what I want to do is activate the plugin so activate and then in the front end uh let's go to the Javascript file and just give an alert we'll say alert one okay so now you can see that that JavaScript is now included okay we'll delete that so that's all set the next thing we want to do is include our class file okay so we'll say include class you should you should have your code um well commented so this will add add our JavaScript okay include class we're going to use include and class do it's in the same directory so just do class. likebox do PHP okay that'll include our class and then the last thing we want to do in this file is uh register our widget and then all the rest of the code will be pretty much in the class all right so to do this we want to say function register like box okay and then we're going to call register uncore widget and let's see we're going to pass in likebox underscore widget and then we need to use the add action hook again so add action okay we're going to use uh widgets underscore and nit and then the name of our function which is register like box all right so that's basically all the code we need for this main file all right the rest of the stuff is going to go into our class and we will get into that in the next part
Original Description
In this series we will build a Facebook likebox widget with multiple parameters
-- Exercise Files - https://github.com/codeskillet/likebox
-- For more web development videos, visit http://codeskillet.com
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Traversy Media · Traversy Media · 41 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
▶
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Changing Your DNS/Nameservers
Traversy Media
Create a MySQL database in cPanel
Traversy Media
Install & Uninstall Joomla Extensions
Traversy Media
Adding and linking an article in Joomla
Traversy Media
Create a Joomla Blog
Traversy Media
Import & Export A MySQL Database
Traversy Media
Use A Custom Font On Your Website Using CSS
Traversy Media
Connect Joomla Site With Dreamweaver
Traversy Media
Remove Phoca Gallery 3.2.3 Footer Text
Traversy Media
Drupal 7 Security Update 7.19 to 7.20
Traversy Media
Add An Addon Domain In Cpanel
Traversy Media
Pull A Heroku Rails App and Database
Traversy Media
Create a Custom Joomla 2.5 Module - Part 1
Traversy Media
Create a Custom Joomla 2.5 Module - Part 2
Traversy Media
Create a Custom Joomla 2.5 Module - Part 3
Traversy Media
Joomla SEO Tutorial - sh404sef Configuration
Traversy Media
Font Dragr
Traversy Media
Convert an HTML Template to Joomla 2.5/3.0 - Part One
Traversy Media
Convert an HTML Template to Joomla 2.5/3.0 - Part Two
Traversy Media
Rockettheme Rocketlauncher Joomla Site in Under 10 Minutes
Traversy Media
JQuery FAQ Slider Tutorial
Traversy Media
301 Redirect With htaccess File
Traversy Media
Convert HTML to Wordpress Theme - Part 1
Traversy Media
Convert HTML to Wordpress Theme - Part 2
Traversy Media
Easy JQuery Widgets
Traversy Media
Codeigniter App Part 1 - Creating the Database
Traversy Media
Codeigniter App Part 2 - Installation and Configuration
Traversy Media
Codeigniter App Part 6 - Login/Register System
Traversy Media
Codeigniter App Part 7 - Models List CRUD
Traversy Media
Codeigniter App Part 8 - Models Task CRUD
Traversy Media
Node.js Part 1 - Install NodeJS on Windows
Traversy Media
Node.js Part 3 - Building a Static Page Server
Traversy Media
Node.js Part 4 - NPM
Traversy Media
Node.js Part 2 - Install MongoDB in Windows
Traversy Media
Create a Joomla Quickstart with Custom Sample Data
Traversy Media
Install MongoDB in Ubuntu
Traversy Media
HTML5 Web Storage
Traversy Media
Create a Joomla Bootstrap Template From Scratch
Traversy Media
Ubuntu Server 14.04 Setup Part 1 - Installation
Traversy Media
Ubuntu Server 14.04 Setup Part 3 - Set Static IP
Traversy Media
Create A Wordpress Widget - Part 1
Traversy Media
Create A Wordpress Widget - Part 2
Traversy Media
Create A Wordpress Widget - Part 3
Traversy Media
Create A Wordpress Widget - Part 4
Traversy Media
Get Started With Sass on Windows
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 1
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 6
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 4
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 5
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 3
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 2
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 7
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 10
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 8
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 11
Traversy Media
Build An HTML5 Template With Bootstrap and SASS - Part 9
Traversy Media
Build An Audio Player Using HTML5 & jQuery - Part 1
Traversy Media
Build An Audio Player Using HTML5 & jQuery - Part 2
Traversy Media
Youtube Data API v3 & jQuery To List Channel Videos
Traversy Media
Using Bootstrap With Ruby on Rails
Traversy Media
More on: Systems Design Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI