Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,228 members, 8,001,967 topics. Date: Wednesday, 13 November 2024 at 08:08 PM

Custom Wordpress Widget Development Tutorial(in OOP) - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Custom Wordpress Widget Development Tutorial(in OOP) (721 Views)

Hide Any Wordpress Widget On Mobile Devices With This Plugin / Blogging Tips: How To Make A Widget Visible In Mobile View / Steps To Add A Widget Below First Post In Blogger (2) (3) (4)

(1) (Reply) (Go Down)

Custom Wordpress Widget Development Tutorial(in OOP) by dwebdesign(m): 9:23am On Oct 26, 2015
Morning, we all use wordpress and sometimes we imagine how to have a widget that does a particular function and is styled in a particular way either using LESS or SASS or Normal CSS.

This morning, i want to share how you can create your own custom wordpress widget, though writing wordpress widget is OOP based, that is its Object Oriented Programming because we will use the PHP OOP keyword "Extends" to extend the "WP_Widget" class so we can have access to all of its methods and properties. for this tutorial to make more sense to you, i will suggest if you don't know anything about OOP, you can search for "PHP OOP" on google.

Just stick with me here and you will get something new learnt today,

First is that we will have to stub out our widget, from header definition to the class instanciaition ,

so we start:

go to your wordpress plugins folder, create a new folder and call it "nairaland widget" then create a file called "index.php" and paste the code below:, after that go to your dashboard->plugins and activate it. then go to appearance-> widgtes , you should see it listed out. you can then drag and drop it in any sidebar you want and save it.

<?php
/**
*Plugin Name: Nairaland Widget
*Plugin URI: https://www.nairaland.com/nairaland_widget
*Author: Seun
*Author URI: http://www.seunosewa.com/
*version: 1.0
*Description: This plugin demonstrates how to build a wordpress widget from scratch
*License: GPL2 OR LATTER *because wordpress is GPL
*/

//Now we will then lay out the structure:

class Nairaland_Widget extends WP_Widget{

//function that is run when we instantiate the class

function __construct(){


}

//the function that displays the form in the backend

function form ($instance){


}

//function that will update values passed into the from and compare both to save the new values
function update($new_instance , $old_instance){


}

//function that displays the widget on the frontend of the website

function widget($args, $instance ){


}




}

?>

In next class, we will start the actual coding and building of the wordpress widget plugin.

like to show interest so i can start the second part to know if people are interested.

Many thanks.

for coaching on web design and development, comment below.
Re: Custom Wordpress Widget Development Tutorial(in OOP) by kinzation(m): 10:03am On Oct 26, 2015
Give me more.....
Re: Custom Wordpress Widget Development Tutorial(in OOP) by 5moky: 11:02am On Oct 26, 2015
@OP , no matter how cool you act. You are who everybody thinks you are.
well, following you like magnet.. But this your thread, you sure say no be copy and paste? lol
Re: Custom Wordpress Widget Development Tutorial(in OOP) by dwebdesign(m): 2:56pm On Oct 26, 2015
5moky:
@OP , no matter how cool you act. You are who everybody thinks you are.
well, following you like magnet.. But this your thread, you sure say no be copy and paste? lol

@smoky, verify case before you start saying stuff.

what do they think i am?

I don't understand.

@kinzation, next class soonest.

(1) (Reply)

How I Got Google Adsense With Ease Within A Week / Facebook Profile Forsale! / Nairalanders Should Help Me Review Dis Blog

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.