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



    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; ? >

Let's build a better web together

Get in touch with us for a quick quote

Web Development Agency, We Website Design

We’re eCommerce Experts in Cutting-edge Design & Development Technologies - Worldwide accreditation from leading digital platform providers including Shopify, WordPress & Magento.

Web Development Agency Manchester

Woolden Road
M44 5JX

Web Development Agency London

71-75 Shelton Street
Covent Garden

Let's hook up


0161 676 8989

Stalk Us On Social

What We Do

  • Shopify
  • WordPress
  • Magento
  • SEO
  • Aero Commerce
  • Shopify 2.0

Copyright 2022 We Agency - White Label Web Development Digital Agency.
Registered in England & Wales We Agency is a trading division of We Website Design Ltd. Company Registration Number 14175442 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.