Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

Add Items to a WordPress Navigation ul


WordPress
David Egan

Add a button as the last item in a WordPress navigation:

  add_filter('wp_nav_menu_items','carawebs_payment_button', 10, 2);

function carawebs_payment_button($items, $args) {

  if (!is_admin() && $args->theme_location == 'primary_navigation') {

  $items .= '<li class="pay-button"><a href="http://#"><button>Click</button></a></li>';



  }

  return $items;
}

Add a search form as the last item in a WordPress navigation:

  add_filter('wp_nav_menu_items','carawebs_payment_button', 10, 2);

function carawebs_payment_button($items, $args) {

  if (!is_admin() && $args->theme_location == 'primary_navigation') {

  ob_start();
  get_search_form();
  $searchform = ob_get_contents();
  ob_end_clean();

  $items .= '<li class="search">Search ' . $searchform . '</li>';

  }

  return $items;
}

comments powered by Disqus