WordPress.org

Ready to get started?Download WordPress

Forums

Disabling current page menu items (3 posts)

  1. Brico
    Member
    Posted 6 years ago #

    I looked everywhere for a solution and found nothing that woul;d enable me to disable curent page menu items retrieved through

    wp_list_pages()

    Having the current menu item clickable and thus reloading the page didn't seem like good practice to me.

    Eventually I resorted to hacking the 'template-functions-post.php'. I changed these lines in the '_page_level_out' function:

    ========================

    $css_class = 'page_item';
    		if ( $page_id == $queried_obj->ID )
    			$css_class .= ' current_page_item';
    
    			$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . $title . '">' . $title . '</a>';

    =========================

    to

    =========================

    $css_class = 'page_item';
    		if ( $page_id == $queried_obj->ID ){
    			$css_class .= ' current_page_item';
    			$output .= $indent . '<li class="' . $css_class . '"><strong>' . $title . '</strong>';
    		}else{
    			$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . $title . '">' . $title . '</a>';
    		}

    ========================

    It worked like a dream.

    Brico

  2. Brico
    Member
    Posted 6 years ago #

    I realised that the version of wordpress I was working with was an early version (2.0.5). For the current version (2.2.3) you have to hack 'classes.php' in the folder 'wp-includes'.

    The lines you should look for are in class Walker_Page:

    change from
    ==================================

    if ( $page->ID == $current_page )
    			$css_class .= ' current_page_item';
    
    		elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    			$css_class .= ' current_page_parent';
    
    		$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';

    ===============================
    to
    ===============================

    if ( $page->ID == $current_page ){
    			$css_class .= ' current_page_item';
    			$output .= $indent . '<li class="' . $css_class . '"><strong>' . apply_filters('the_title', $page->post_title) . '</strong>';
    		}elseif ( $_current_page && $page->ID == $_current_page->post_parent ){
    			$css_class .= ' current_page_parent';
    			$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
    }else{
    		$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
    }

    ===============================

    REMEMBER TO BACK UP THE FILE FIRST

    All the best, Brico

  3. Anonymous
    Unregistered
    Posted 5 years ago #

    Wouldn't it just be easiest to do it with css? li.current_page_item { display:none; } ? any thoughts?

Topic Closed

This topic has been closed to new replies.

About this Topic