{"id":4953,"date":"2017-06-17T17:28:41","date_gmt":"2017-06-17T17:28:41","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=4953"},"modified":"2025-04-23T09:41:53","modified_gmt":"2025-04-23T09:41:53","slug":"how-to-create-custom-widget-in-wordpress","status":"publish","type":"post","link":"\/uk\/tutorials\/how-to-create-custom-widget-in-wordpress","title":{"rendered":"How to Create WordPress Custom Widgets: What They Are and How They Work?"},"content":{"rendered":"<p>Did you know that you can create your own WordPress custom widget? While there are tons of additional widgets that come alongside themes and plugins, WordPress offers its users the option to code custom widgets manually.<\/p><p>It&rsquo;s not a complicated process as you only need basic knowledge of WordPress and PHP. So, without further ado, let&rsquo;s get started!<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\" target=\"_blank\" rel=\"noopener\">Download all in one WordPress cheat sheet<\/a><\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-are-wordpress-widgets\">What Are WordPress Widgets?<\/h2><p>WordPress widgets make it easy for you to add additional functions to your website through a simple drag-and-drop interface. By default, WordPress ships with several widgets. They provide you with basic utility features and are compatible with every WordPress theme.<\/p><p>However, sometimes, those standard widgets can&rsquo;t perform the tasks you want. Your best option is to look for plugins offering you the desired function. Unfortunately, you might find that even third-party plugins can&rsquo;t fulfill your requirements.<\/p><p>Thankfully, you have the power to create a WordPress custom widget. Just keep in mind that it has to be built from the ground-up so you can personally fine-tune your custom widget based on your needs.<\/p><h2 class=\"wp-block-heading\" id=\"h-where-to-begin-when-creating-a-custom-widget\">Where to Begin When Creating a Custom Widget?<\/h2><p>First, you need to choose whether you want to create the widget using a plugin or via editing the <a href=\"\/uk\/tutorials\/functions-php-wordpress\">functions.php<\/a> file. A plugin will enable the custom widget to work on any site while adding code to <strong>functions.php<\/strong>. This way, it makes the widget work alongside a specific theme.<\/p><p>Secondly, you have the option to add the widget on a live site or in a local environment. However, we highly recommend you to implement the widget in a local environment first, to test it out. You can easily do this by following our guide on how to run <a href=\"\/uk\/tutorials\/run-docker-wordpress\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress on Docker<\/a>.<\/p><p>Once the tool is working correctly, it is time to move it to your website.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-do-wordpress-custom-widgets-work\">How Do WordPress Custom Widgets Work?<\/h2><p>In WordPress, you have to create a custom widget using the standard <strong><a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_widget\/\" target=\"_blank\" rel=\"noopener\">WP Widget<\/a><\/strong> class from the <strong><a href=\"https:\/\/codex.wordpress.org\/Widgets_API\" target=\"_blank\" rel=\"noopener\">Widgets API<\/a><\/strong>. There are around 20 functions that you can play around with. Out of these, <strong>four<\/strong> is the minimum requirement for any widget to work:<\/p><ul class=\"wp-block-list\">\n<li><strong>__construct()<\/strong> &ndash; constructor function where you can define your widget&rsquo;s parameters.<\/li>\n\n\n\n<li><strong>widget()<\/strong> &ndash; contains the output of the widget.<\/li>\n\n\n\n<li><strong>form()<\/strong> &ndash; determines widget settings in the WordPress dashboard.<\/li>\n\n\n\n<li><strong>update()<\/strong> &ndash; updates widget settings.<\/li>\n<\/ul><p>Of course, you&rsquo;ve got plenty of other options that provide additional functions. For more on the <strong>WP_Widget<\/strong> class, take a look at the WordPress <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_widget\/\" target=\"_blank\" rel=\"noopener\">developer page<\/a>.<\/p><h2 class=\"wp-block-heading\" id=\"h-creating-a-wordpress-custom-widget\">Creating a WordPress Custom Widget<\/h2><p>\n\n\n<div><p class=\"important\"><strong>Important!<\/strong> It&rsquo;s strongly recommended to create a full <a href=\"\/uk\/tutorials\/backups\/downloading-website-backup\">website backup<\/a> before proceeding further. In addition, you should also use a WordPress <a href=\"\/uk\/tutorials\/how-to-create-wordpress-child-theme\">child theme<\/a> to prevent any issues from affecting your main theme.<\/p><\/div>\n\n\n\n<\/p><p>For this tutorial, we&rsquo;ll be creating a simple <strong>&ldquo;Greetings from Hostinger.com!&rdquo;<\/strong> custom widget so you can learn the basics of widget creation in WordPress. Once that is done, you can move on to creating more complex widgets on your own.<\/p><p>One more thing to note is that we&rsquo;re writing this code in the <strong>functions.php<\/strong> file for the currently loaded theme. That being said, you can use the same code for any custom plugin.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-extending-the-wp-widget-class\">1. Extending the WP_Widget class<\/h3><p>The first thing you need to do is to open any text editor on your computer and create a new class that extends the base <strong>WP_Widget<\/strong> class, like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class hstngr_widget extends WP_Widget {\n\/\/Insert functions here\n}<\/pre><h3 class=\"wp-block-heading\" id=\"h-2-adding-construct\">2. Adding __construct()<\/h3><p>Next, we start implementing the four standard functions one by one. The first one is the constructor method, which will determine the custom widget&rsquo;s ID, name, and description.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function __construct() {\nparent::__construct(\n\/\/ widget ID\n'hstngr_widget',\n\/\/ widget name\n__('Hostinger Sample Widget', 'hstngr_widget_domain'),\n\/\/ widget description\narray ( 'description' =&gt; __( 'Hostinger Widget Tutorial', 'hstngr_widget_domain' ), )\n);\n}<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-adding-widget\">3. Adding widget()<\/h3><p>Now, let&rsquo;s focus on the <strong>widget()<\/strong> function. It defines the look of your WordPress custom widget on the front-end.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function widget( $args, $instance ) {\n$title = apply_filters( 'widget_title', $instance['title'] );\necho $args['before widget'];\n\/\/if title is present\nIf ( ! empty ( $title ) )\nEcho $args['before_title'] . $title . $args['after_title'];\n\/\/output\necho __( 'Greetings from Hostinger.com!', 'hstngr_widget_domain' );\necho $args['after_widget'];\n}<\/pre><p>With this, we have configured the output of our widget so that it displays the phrase <strong>&ldquo;Greetings from Hostinger.com!&rdquo;<\/strong> and widget&rsquo;s title as specified by the user.<\/p><h3 class=\"wp-block-heading\" id=\"h-4-adding-form\">4. Adding form()<\/h3><p>Now, we have to program the back-end of the widget using the<strong> form()<\/strong> method. You can see the result when you want to add the widget from the WordPress Dashboard.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function form( $instance ) {\nif ( isset( $instance[ 'title' ] ) )\n$title = $instance[ 'title' ];\nelse\n$title = __( 'Default Title', 'hstngr_widget_domain' );\n?&gt;\n&lt;p&gt;\n&lt;label for=\"&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;\"&gt;&lt;?php _e( 'Title:' ); ?&gt;&lt;\/label&gt;\n&lt;input class=\"widefat\" id=\"&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;\" name=\"&lt;?php echo $this-&gt;get_field_name( 'title' ); ?&gt;\" type=\"text\" value=\"&lt;?php echo esc_attr( $title ); ?&gt;\" \/&gt;\n&lt;\/p&gt;\n&lt;?php\n}<\/pre><p>Here you can see how a custom widget has been set up. If a user applies a title, then that title will be inserted in the HTML form we created. In this example, we will set the name of the title to <strong>Default Title<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"309\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/widget-back-end-1024x309.png\" alt=\"Giving your WordPress custom widget a title\" class=\"wp-image-20180\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-1024x309.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-150x45.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-300x91.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-768x232.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-990x299.png 990w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end-1320x399.png 1320w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/widget-back-end.png 1886w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-5-adding-update\">5. Adding update()<\/h3><p>Once that&rsquo;s done, we have to implement <strong>update()<\/strong>, which will refresh the widget every time you change the settings.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function update( $new_instance, $old_instance ) {\n$instance = array();\n$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';\nreturn $instance;\n}<\/pre><p>We&rsquo;re taking the current title of the newly created instance, removing any HTML\/PHP tags. Then, we&rsquo;re passing the title to the instance and returning it.<\/p><h3 class=\"wp-block-heading\" id=\"h-6-registering-wordpress-custom-widget\">6. Registering WordPress Custom Widget<\/h3><p>Finally, we have to register the new custom widget using <strong>add_action()<\/strong> function. Keep in mind that you should place the following code at the top, before extending the <strong>WP_Widget<\/strong> class.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function hstngr_register_widget() {\nregister_widget( 'hstngr_widget' );\n}\nadd_action( 'widgets_init', 'hstngr_register_widget' );<\/pre><h2 class=\"wp-block-heading\" id=\"h-adding-the-code-to-functions-php-file\">Adding the Code to functions.php File<\/h2><p>So, we&rsquo;ve defined a new function called <strong>hstngr_register_widget()<\/strong>. It registers our widget using the widget ID, which is specified in the <strong>__construct()<\/strong> function.<\/p><p>Then, we have tied this function using <strong>widgets_init<\/strong>, which loads the widget into WordPress through the built-in <strong>add_action()<\/strong> method. Your final WordPress custom widget code should look like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function hstngr_register_widget() {\nregister_widget( 'hstngr_widget' );\n}\nadd_action( 'widgets_init', 'hstngr_register_widget' );\nclass hstngr_widget extends WP_Widget {\nfunction __construct() {\nparent::__construct(\n\/\/ widget ID\n'hstngr_widget',\n\/\/ widget name\n__('Hostinger Sample Widget', ' hstngr_widget_domain'),\n\/\/ widget description\narray( 'description' =&gt; __( 'Hostinger Widget Tutorial', 'hstngr_widget_domain' ), )\n);\n}\npublic function widget( $args, $instance ) {\n$title = apply_filters( 'widget_title', $instance['title'] );\necho $args['before_widget'];\n\/\/if title is present\nif ( ! empty( $title ) )\necho $args['before_title'] . $title . $args['after_title'];\n\/\/output\necho __( 'Greetings from Hostinger.com!', 'hstngr_widget_domain' );\necho $args['after_widget'];\n}\npublic function form( $instance ) {\nif ( isset( $instance[ 'title' ] ) )\n$title = $instance[ 'title' ];\nelse\n$title = __( 'Default Title', 'hstngr_widget_domain' );\n?&gt;\n&lt;p&gt;\n&lt;label for=\"&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;\"&gt;&lt;?php _e( 'Title:' ); ?&gt;&lt;\/label&gt;\n&lt;input class=\"widefat\" id=\"&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;\" name=\"&lt;?php echo $this-&gt;get_field_name( 'title' ); ?&gt;\" type=\"text\" value=\"&lt;?php echo esc_attr( $title ); ?&gt;\" \/&gt;\n&lt;\/p&gt;\n&lt;?php\n}\npublic function update( $new_instance, $old_instance ) {\n$instance = array();\n$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';\nreturn $instance;\n}\n}<\/pre><p>Finally, it is time to insert the code to your <strong>functions.php<\/strong> file.<\/p><ol class=\"wp-block-list\">\n<li>Log in to your WordPress admin area. Then, navigate to <strong>Appearance<\/strong> -&gt; <strong>Theme Editor<\/strong> -&gt; <strong>Theme Functions<\/strong>.<\/li>\n\n\n\n<li>Paste the code from your text editor to the bottom of <strong>functions.php<\/strong> file. Click <strong>Update File<\/strong> to save the changes.<\/li>\n<\/ol><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"415\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/editing-functions-php-file-1024x415.png\" alt=\"Adding custom widget code to functions.php file in WordPress\" class=\"wp-image-20182\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-1024x415.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-150x61.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-300x122.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-768x312.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-990x402.png 990w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file-1320x535.png 1320w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/editing-functions-php-file.png 1526w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-using-wordpress-custom-widget\">Using WordPress Custom Widget<\/h2><p>You can finally use your newly-installed widget.<\/p><ol class=\"wp-block-list\">\n<li>Go to the <strong>Appearance<\/strong> menu, and select <strong>Widgets<\/strong>. You should see a widget named <strong>Hostinger Sample Widget<\/strong> in the <strong>Available Widgets<\/strong> list.<\/li>\n\n\n\n<li>Next, drag the widget and drop it in the <strong>Sidebar<\/strong> section on the right side of the page.<br><img decoding=\"async\" class=\"aligncenter wp-image-20184 size-large\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/hostinger-sampe-widget-1024x447.png\" alt=\"Dragging and dropping a custom widget to the sidebar in WordPress\" width=\"1024\" height=\"447\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-1024x447.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-150x65.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-300x131.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-768x335.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-990x432.png 990w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget-1320x576.png 1320w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sampe-widget.png 1887w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/li>\n\n\n\n<li>Save your changes and visit your website. You will be welcomed with a custom widget with the words <strong>&ldquo;Greetings from Hostinger.com&rdquo;<\/strong> inside.<\/li>\n<\/ol><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"340\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/hostinger-sample-widget-1024x340.png\" alt=\"WordPress custom widget final result\" class=\"wp-image-20396\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-1024x340.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-150x50.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-300x100.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-768x255.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-414x138.png 414w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-990x329.png 990w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget-1320x438.png 1320w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2017\/06\/hostinger-sample-widget.png 1681w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div><p>Congratulations, you have successfully created your first custom WordPress widget!<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>WordPress custom widget allows you to add a specific function to your website based on your needs. It&rsquo;s a great solution whenever you can&rsquo;t find anything in particular that would meet your specific requirements. or when you&rsquo;re <a href=\"\/uk\/tutorials\/how-to-become-wordpress-developer\">becoming a WordPress developer<\/a> and want to develop your website.<\/p><p>To summarize, let&rsquo;s take a look at the steps once again on how to create your own custom WordPress widget:<\/p><ol class=\"wp-block-list\">\n<li>Create a new class that extends <strong>WP_Widget<\/strong>.<\/li>\n\n\n\n<li>Begin with <strong>__construct()<\/strong> to determine widget&rsquo;s parameters.<\/li>\n\n\n\n<li>Use <strong>widget()<\/strong>&nbsp;to define the appearance of the widget on the front-end.<\/li>\n\n\n\n<li>Add <strong>form()<\/strong> to configure how the widget will look.<\/li>\n\n\n\n<li>Don&rsquo;t forget to add <strong>update()<\/strong> to refresh the widget every time you modify it.<\/li>\n\n\n\n<li>Register the new WordPress custom widget using <strong>add_action()<\/strong> function.<\/li>\n\n\n\n<li>Copy and paste the entire code to the bottom of <strong>functions.php<\/strong> file and click <strong>Update File<\/strong>.<\/li>\n\n\n\n<li>Go to the <strong>Widgets<\/strong> menu and move the widget to the desired place.<\/li>\n<\/ol><p>Good luck!<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Discover More Expert WordPress Techniques<\/h4>\n                    <p><a href=\"\/uk\/tutorials\/wordpress-template-hierarchy\">WordPress Template Hierarchy<\/a><br>\n<a href=\"\/uk\/tutorials\/wordpress-custom-post-types\">How to Create Custom Post Types in WordPress<\/a><br>\n<a href=\"\/uk\/tutorials\/wordpress-page-template\">How to Create Custom WordPress Page Templates<\/a><br>\n<a href=\"\/uk\/tutorials\/wordpress-post-template\">How to Create a Custom WordPress Post Template<\/a><br>\n<a href=\"\/uk\/tutorials\/how-to-setup-and-manage-a-wordpress-cron-job\">How to Setup and Manage Cron Jobs in WordPress<\/a><br>\n<a href=\"\/uk\/tutorials\/how-to-add-php-code-to-wordpress-post-or-page\">How to Add PHP to WordPress<\/a><\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that you can create your own WordPress custom widget? While there are tons of additional widgets that come alongside themes and plugins, WordPress offers its users the option to code custom widgets manually. It&rsquo;s not a complicated process as you only need basic knowledge of WordPress and PHP. So, without further ado, [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/how-to-create-custom-widget-in-wordpress\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Create WordPress Custom Widgets: A Step-by-Step Guide","rank_math_description":"Need more out of your WordPress website? Learn how to create your very own WordPress custom widget in this step-by-step guide.","rank_math_focus_keyword":"wordpress custom widget","footnotes":""},"categories":[22637,22633],"tags":[],"class_list":["post-4953","post","type-post","status-publish","format-standard","hentry","category-customization-and-design","category-wordpress"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-criar-widget-wordpress","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/creer-un-widget-wordpress","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/crear-widgets-wordpress-personalizados","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/crear-widgets-wordpress-personalizados","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/crear-widgets-wordpress-personalizados","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/crear-widgets-wordpress-personalizados","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-criar-widget-wordpress","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-create-custom-widget-in-wordpress","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/4953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=4953"}],"version-history":[{"count":39,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/4953\/revisions"}],"predecessor-version":[{"id":100274,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/4953\/revisions\/100274"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=4953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=4953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=4953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}