wordpress - how to get rid of parent menu item in sidebar

Posted on 2010-11-23
Medium Priority
Last Modified: 2012-08-13
Notice on this page how the "In The News" section is highlighted.


There is also an "In the News" header at the top of the sidebar:
<h2 class="sidebartitle">In the News</h2>

I don't want this h2 to show when I go to the "In the News" page. I just want the "In the News" link to show. The one that is currently below the "Plasticos Foundation" link in the sidebar.

Question by:phillystyle123
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 17

Expert Comment

ID: 34200330
edit sidebar.php to not display that h2 if on that page...

can you post the contents or upload your sidebar.php?

Author Comment

ID: 34200549
Thanks for the reply,

sidebar attached. Actually, what I'd really like to do is to list a page that is using "In the News" as a parent underneath the "In the News" link so if you were on this page:


<h2 class="sidebartitle">In the News</h2> wouldn't appear and the sidebar would output as follows:

Plasticos Foundation
In the News
>Articles (In the News is the parent)
Read Our Blog

Perhaps I need to make the "In the News link go away instead?
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    global $notfound;
    if (is_page() and ($notfound != '1')) {
        $current_page = $post->ID;
        while($current_page) {
            $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
            $current_page = $page_query->post_parent;
        $parent_id = $page_query->ID;
        $parent_title = $page_query->post_title;
        // if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) {
        if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_type != 'attachment'")) {

    <?php } } ?>
		<?php wp_list_categories('sort_column=name&optioncount=1&hierarchical=0&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>'); ?>
    <li class="widget">
      <h2 class="sidebartitle"><?php _e('Archives'); ?></h2>
      <ul class="list-archives">
        <?php wp_get_archives('type=monthly'); ?>
    <li class="widget">
      <h2 class="sidebartitle"><?php _e('Links'); ?></h2>
      <ul class="list-blogroll">
			$links = get_bookmarks('orderby=name&order=ASC&limit=-1'); 
			foreach($links as $link){
				echo '<li><a href="'.$link -> link_url.'">'.$link -> link_name.'</a></li>';
	<li class="widget">
      <h2 class="sidebartitle">Meta</h2>
      <ul class="list-meta">
		<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>"><?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
		<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
		<li><a href="http://mythem.es/" title="mythem.es">My Themes</a></li>
		<?php wp_meta(); ?>
  <?php endif; ?>
<!--/sidebar -->

Open in new window

LVL 17

Expert Comment

ID: 34200630
ok so to get rid of the <h2> at the top of the sidebar


&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>'

from the call to wp_list_categories at linie 24 above

In order to do what you are specifying as far as listing pages under a specific category, you can do that but there isn't a function to just do it, you will have to get your data and then run some replaces to inject the pages into the correct spot.
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.


Author Comment

ID: 34200690
i only want to get rid of it for the "In the News" page - is there some sort of conditional I can use ala
<?php if ( is_front_page() ) { ?>?
LVL 17

Expert Comment

ID: 34200720
unfortunately, not that I know of. You will most likely need to build the menu yourself using get_categories
LVL 17

Accepted Solution

jrm213jrm213 earned 2000 total points
ID: 34200802
oh you know what you could do though...

you could use

if is_category to surround the whole statement and use two different wp_list_categories calls. I initially thought you meant a conditional for inside the wp_list_categories parameter string...

if is_category(['id,title or slug  of your category'])
wp_list_categories('sort_column=name&optioncount=1&hierarchical=0&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>');

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question