Skip to content

Instantly share code, notes, and snippets.

@WhiteHatJoker
Created October 18, 2021 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WhiteHatJoker/a565f9ca347953970d2748161cbf9486 to your computer and use it in GitHub Desktop.
Save WhiteHatJoker/a565f9ca347953970d2748161cbf9486 to your computer and use it in GitHub Desktop.
If you are not satisfied with the amount of menu areas or widget areas provided by your theme, you can use the code from this repository to add extra menus or widgets or both.

Adding Extra Menus or Widgets

If you are not satisfied with the amount of menu areas or widget areas provided by your theme, you can use the code from this repository to add extra menus or widgets or both.

Installation for Menus

  1. Copy the lines 3-13 from functions.php of current repository and place it in your functions.php file.
  2. In your template file, wherever you would like your custom menu to appear add the following <?php wp_nav_menu( array('menu' => 'Header Menu' )); ?>.
  3. If you want to add more than one custom menu just add new line into an array in place of comments on line 8, for example, , 'footer-menu' => __( 'Footer Menu' ).

Installation for Widgets

  1. Copy the lines 15-32 from functions.php of current repository and place it in your functions.php file.
  2. In your template file, wherever you would like your custom widget to appear add the following <?php if ( ! dynamic_sidebar( 'head' ) ); ?>.
  3. It is simple, now you have the new widget area in your Appearance->Widgets called Header to fill in the widget.
  4. If you want to add more than one widget are just copy the code from line 30 and paste it below replacing function's parameters with your prefered naming.
<?php
// Function for adding extra custom menus
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
//Create extra menus here, but you would still need to call them in template where you would like them to appear
)
);
}
add_action( 'init', 'register_my_menus' );
// Function for creating extra widgets
function create_widget($name, $id, $description) {
register_sidebar(array(
'name' => __( $name ),
'id' => $id,
'description' => __( $description ),
'before_widget' => '<div id="'.$id.'" class="widget %1$s %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
create_widget("Header", "head", "Displays in the header of the site");
//Copy the code above and replace the function parameters with new information to created additional widgets for your wordpress
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment