wp_page_menu

Definition:
function wp_page_menu( $args = array() {}

Display or retrieve list of pages with optional home link.
The arguments are listed below and part of the arguments are for wp_list_pages() function. Check that function for more info on those arguments.

Parameters

  • array|string $args

Defined filters

  • wp_page_menu_args
    apply_filters( 'wp_page_menu_args', $args )
  • wp_page_menu
    apply_filters( 'wp_page_menu', $menu, $args )

Source code

function wp_page_menu( $args = array() ) {

	$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');

	$args = wp_parse_args( $args, $defaults );

	$args = apply_filters( 'wp_page_menu_args', $args );



	$menu = '';



	$list_args = $args;



	// Show Home in the menu

	if ( ! empty($args['show_home']) ) {

		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )

			$text = __('Home');

		else

			$text = $args['show_home'];

		$class = '';

		if ( is_front_page() && !is_paged() )

			$class = 'class="current_page_item"';

		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';

		// If the front page is a page, add it to the exclude list

		if (get_option('show_on_front') == 'page') {

			if ( !empty( $list_args['exclude'] ) ) {

				$list_args['exclude'] .= ',';

			} else {

				$list_args['exclude'] = '';

			}

			$list_args['exclude'] .= get_option('page_on_front');

		}

	}



	$list_args['echo'] = false;

	$list_args['title_li'] = '';

	$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );



	if ( $menu )

		$menu = '<ul>' . $menu . '</ul>';



	$menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";

	$menu = apply_filters( 'wp_page_menu', $menu, $args );

	if ( $args['echo'] )

		echo $menu;

	else

		return $menu;

}

3969

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: