Holt DevOps News

How to build a custom Widget in WordPress

News Categories: Wordpress

This article was published on: 03/24/20 9:31 AM

How to build a custom Widget in WordPress

Building a custom Widget in WordPress is a simple take if you understand the basics of the platform, where all the files are stored in on the server and a little bit about PHP.

Let’s dive right in and locate your Functions.php file within your WordPress theme directory, this is the usual path.

/wp-content/themes/my-theme-name – if it’s a standard WordPress theme then it could be called ‘twentytwenty’

Inside Functions.php paste this code in after ); This is the end of a function and its ready to start a new one, if you paste within a function it will either break the site (just undo and save to fix) or disable that function within the site.

function holthub_widgets_init() {

	register_sidebar( array(
		'name' => 'WIDGET NAME',
		'id' => 'widgetid',
		'before_widget' => '
‘, ‘after_widget’ => ‘

‘, ) ); } add_action( ‘widgets_init’, ‘holthub_widgets_init’ );

In the 'before_widget' => '

‘, you can add a class or change to another tag – ‘before_widget’ => ‘

‘, or changed to a

,

or

    depending on what you are adding to the widget.

Paste this into your PHP code (template) to display on the front end.

< ? php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('widgetid') ) : endif; ? >

This is an epic footer, don't you think?

We’re Hardcore Experts in Cutting-edge Design & Development Technologies - Worldwide accreditation from leading digital platform providers

Web Development Agency Manchester

The Barn
Woolden Road
Manchester
M44 5JX


Stalk Us On Social

Web Development Agency London

71-75 Shelton Street
Covent Garden
London
WC2H 9JQ


Let's hook up

hello@holtdevops.com

0161 676 8989

Copyright 2021 Holt DevOps Ltd - White Label Web Development Digital Agency | 13127888 Registered in England and Wales | Privacy Policy

Ready to work with us?

Drop us your details and we will arrange a social distanced meet & greet or video chat so you can see our beautiful faces.

    Name*

    Email*

    Telephone