• Resolved The Night Fox

    (@the-night-fox)


    I want to nofollow the contact us and privacy policy page in my navbar, but I can’t figure out how to do it and keep the themes CSS intact.

    Header.php:

    <div id="navmenu">
    				<ul>
    					<li<?php echo (is_home() ? ' class="current_page_item"': '')?>><a href="<?php echo get_option('home'); ?>/"><span>Home</span></a></li>
    					<?php themefunction_list_pages_flat('title_li='); ?>
    				</ul>
    			</div>

    style-section-navigation.css:

    }
    div#navmenu ul li a:hover { background: transparent url('images/background-navmenu-item-hover-left.gif') left top no-repeat; text-decoration: none; }
    div#navmenu ul li a:hover span { display: block; background: transparent url('images/background-navmenu-item-hover-right.gif') right top no-repeat; color: #00528f; }
    div#navmenu ul li.current_page_item a, div#navmenu ul li.current_page a:visited { background: transparent url('images/background-navmenu-item-hover-left.gif') left top no-repeat; }
    div#navmenu ul li.current_page_item a span, div#navmenu ul li.current_page_item a:visited span { background: transparent url('images/background-navmenu-item-hover-right.gif') right top no-repeat; color: #00528f; }
Viewing 7 replies - 1 through 7 (of 7 total)
  • You’ll need to add the rel="nofollow" inside themefunction_list_pages_flat() which is outputing your navigation links. You can also add it using javascript/jQuery.

    Thread Starter The Night Fox

    (@the-night-fox)

    Hi, thanks for the reply. My theme function looks like this:

    function themefunction_list_pages_flat($args = '') {
    	$defaults = array(
    		'depth' => 0, 'show_date' => '',
    		'date_format' => get_option('date_format'),
    		'child_of' => 0, 'exclude' => '',
    		'title_li' => __('Pages'), 'echo' => 1,
    		'authors' => '', 'sort_column' => 'menu_order, post_title'
    	);

    How can I add the nofollow attribute to it? My PHP/CSS knowledge is quite limited :S

    You need to show me the whole function, not just the first few lines, or else I can’t help you.

    Thread Starter The Night Fox

    (@the-night-fox)

    https://pastebin.com/fbp4LTR0

    Thanks

    Replace, near the bottom,

    $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '"><span>' . apply_filters('the_title', $page->post_title) . '</span></a></li>';

    with

    // Add post ID to nofollow separated by comma
    $nofollow_posts = array(1, 2);
    
    if ( in_array( $page->ID, $nofollow_posts ) )
    	$nofollow = ' rel="nofollow"';
    else
    	$nofollow = '';
    
    $output .= $indent . '<li class="' . $css_class . '"><a '. $nofollow . 'href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '"><span>' . apply_filters('the_title', $page->post_title) . '</span></a></li>';

    and remember to change 1, 2 to the post IDs you want to add nofollow.

    Thread Starter The Night Fox

    (@the-night-fox)

    Thanks for everything Joseph, that worked perfectly!

    You’re welcome.

    Can you please put this as resolved? Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can't Nofollow Links In NavBar’ is closed to new replies.