How to create a custom WordPress widget

WordPress widgets are small snippets of code that can be dragged and dropped into your site’s sidebar for display or, depending on your theme design, other areas of your site.

WordPress includes a selection of basic widgets that you can view by selecting Appearance > Widgets in the admin sidebar. Other widgets can be installed via plugins or you can choose to create custom plugins from your own code.

Open a text editor such as Notepad (Windows) or TextEdit (Mac OS), then copy and paste your code into a new file. Ensure that your plugin code includes a Plugin Name and Description at the top of the file, like this:

<?php
/*
Plugin Name: Test Plugin
Description: Create a custom widget
*/
/* Start Adding Functions Below this Line */
/* Stop Adding Functions Below this Line */
?>

Save the file as mywidget.php (or similar), then compress the file by right-clicking and selecting Send to > Compressed (zipped) folder (Windows) or Compress “mywidget” (Mac).

We now need to upload the file, which we’ll do using cPanel File Manager. Log into the HostPapa dashboard and visit My cPanel. Head to Files > cPanel File Manager to view the files and folders stored on your server.

cPanel

Navigate to your WordPress folder then enter the app > plugins folder.

File Manager

Click the +File button in the command bar and upload your zip file.

Upload file

Select the file, and click Extract in the command bar to decompress the file.

Extract

Now head back to the WordPress admin dashboard and select Plugins. You should see your plugin listed. Be sure to activate by clicking the corresponding link in the dashboard.

Once activated, head to Appearance > Widgets, then drag and drop the custom widget into your sidebar. Save, then navigate to your site’s front page to see the widget in action.

If you notice any problems or if you need any help, please open a new support ticket from your HostPapa Dashboard. More details on how to open a support ticket can be found here.

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache