If you are familiar with WordPress themes then you know that a lot of themes have a widgetized sidebar. This means that you can add, remove sầu, and re-order widgets on your WordPress website by using the “widget” section of your WordPress dashboard.

Bạn đang xem: Widgetizing themes « wordpress codex, how to display custom widget anywhere

Having a widgetized sidebar is very useful, but you may want lớn widgetize other parts of your WordPress theme as well. This is very easy khổng lồ vì chưng, and once your theme is modified it will be simple for you, or the WordPress administrator, khổng lồ swap widgets in and out of different parts of the trang web.

Step 1: Add code to theme

The first step is to add the following line of code khổng lồ the part of your theme that you want to widgetize. Be sure to lớn change “Name of Widgetized Area” to lớn a name that makes sense for you. You will need to do this with a code editor and then upload the tệp tin via a FTP client.

Step 2: Edit functions.php

In your WordPress theme folder, there should be a functions.php file. If there isn’t, just make a new file and name it “functions.php”.

In the functions.php tệp tin, add the following code:

if ( function_exists("register_sidebar") ) register_sidebar(array( "name" => "Name of Widgetized Area", "before_widget" => "
", "after_widget" => "
", "before_title" => "

", "after_title" => "

", ));The code above sầu should be wrapped in PHPhường open & close(, respectively) tags. If you already have sầu a functions.php tệp tin those tags will already be there. If you created one yourself you will have sầu lớn add them.

Xem thêm: Bk Là Gì - Nghĩa Của Từ Bk Trong Tiếng Việt

Make sure lớn change the name of the function (in this case it is “Name of Widgetized Area”) so that it matches the name you gave it in step 1.

The ‘before_widget’ và ‘after_widget’ parameters allow you to lớn specify what code you would lượt thích to lớn put before và after each widget. In this case I put a div with an class for styling purposes.

The ‘before_title’ & ‘after_title’ parameters allow you lớn wrap the widget titles in code. In this case I wrapped the title in


tags respectively.

Step 3: Adding Widgets

Once you have successfully added the widgetized area, you can start adding widgets lớn your WordPress site. To bởi this, log into your WordPress dashboard, then click on Widgets in the Appearance dropdown on the left side.


You should now see the “Name of Widgetized Area” section on the right side of your screen.