Add new widget location on the top page wordpress

To add a new widget location on the top page of a WordPress website, you'll need to follow these steps:

Step 1: Create a new widget area

  1. Log in to your WordPress dashboard.
  2. Go to Appearance > Widgets.
  3. Click on the Add a new widget area button at the top of the page.
  4. Enter a name for your new widget area, such as "Top Page Widgets".
  5. Click Add to create the new widget area.

Step 2: Add the new widget area to your theme

  1. Go to Appearance > Theme Editor.
  2. Open the functions.php file of your theme.
  3. Add the following code at the end of the file:
    function add_top_page_widgets() {
     register_sidebar(array(
         'name' => 'Top Page Widgets',
         'id' => 'top-page-widgets',
         'description' => 'Widgets for the top page',
         'before_widget' => '<div id="%1$s" class="widget %2$s">',
         'after_widget' => '</div>',
         'before_title' => '<h2 class="widget-title">',
         'after_title' => '</h2>',
     ));
    }
    add_action('widgets_init', 'add_top_page_widgets');

    This code registers a new widget area called "Top Page Widgets" with the ID "top-page-widgets".

Step 3: Assign the new widget area to the top page

  1. Go to Appearance > Widgets.
  2. Drag and drop the new widget area ("Top Page Widgets") to the top of the page.
  3. Click Save to save the changes.

Step 4: Add widgets to the new widget area

  1. Go to Appearance > Widgets.
  2. Click on the "Top Page Widgets" widget area.
  3. Add the widgets you want to display on the top page.

Step 5: Update your theme's layout

  1. Go to Appearance > Theme Editor.
  2. Open the header.php file of your theme.
  3. Add the following code before the <nav> or <header> element:
    <?php dynamic_sidebar('top-page-widgets');?>

    This code will display the widgets in the "Top Page Widgets" area.

Step 6: Save and refresh

  1. Save all changes to your theme's files.
  2. Refresh your website to see the new widget area in action.

That's it! You should now have a new widget location on the top page of your WordPress website.