WordPress.org

Ready to get started?Download WordPress

Forums

Nofollow specific links in NavBar? (2 posts)

  1. The Night Fox
    Member
    Posted 3 years ago #

    I'm trying to nofollow specific links in my navbar.

    The code in my header.php looks like this:

    <div id="navmenu-wrapper">
                        <ul>
                            <?php themefunction_page_menu(); ?>
                        </ul>
    </div>

    The code for themefunction_page_menu in my theme fuctions.php looks like this:

    function themefunction_alter_page_menu($string) {
    	$string = themefunction_alter_list_pages($string);
    	$pattern = array('/<div[^<>]*>/','/<\/div[^<>]*>/');
    	$replace = array('','');
    	$string = preg_replace($pattern,$replace,$string);
    	return $string;
    }


    Full theme functions file

    In the past I used the following code to solve this problem, but the code was different and I'm not sure how I can implement it into my theme. Any suggestions would be greatly appreciated!

    Old code:

    // 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>';

    I would then change the array(1, 2); to the post i'ds I wanted to nofollow.

  2. The Night Fox
    Member
    Posted 3 years ago #

    Still stumped on this, anyone have any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.