1

I am new to wordpress and have a project where I have show nav menu category links like this:

<?php wp_nav_menu(array('theme_location' => 'primary', 'menu_class' => 'menu right'));

After adding a new category in the admin, the new category link is not showing in the menu. What should I do about that?

1

A wp_nav_menu is a manually created menu - WordPress doesn't create it for you. If you want to keep using this function, you can go to either Appearance > Menus or Appearance > Customize > Menus, add links to the menu, and check the "primary" theme location under Display Location.

However - if you're just wanting to show category links, it's better to use one of the built-in options so that you don't have to manually add each category and keep them updated.

Option 1: create a sidebar and use the built-in "Categories" widget.

Option 2: pure code:

<?php
$args = array(
  'orderby' => 'name',
  'parent' => 0
  );
$categories = get_categories( $args );
foreach ( $categories as $category ) {
    echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>';
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.