0

I tried to edit original the_post_navigation, inside the loop, so I could get the rel="nofollow" inside of it

the_post_navigation( array(
        'mid_size' => 3,
        'next_text' => __( 'Next frase', 'textdomain' ),
) );

I also tried to use a customized one, but that does not work.

<div class="next-timeline">
   <?php next_post_link( '%link', __( 'Próxima frase', 'adoro-frases-final' ) ); ?>
    <a href="<?php echo $permalink; ?>" rel="nofollow"><?php echo $next_post->post_title; ?></a>
</div>

I also inserted a script to the footer, so it could insert what I want into the link, but it creates another div.a instead.

$( document ).ready(function() {
        $('div.next-timeline > a#lnk-nflw').attr('rel','nofollow')
    });

Any ideas? Thanks!

2
  • 2
    Why would you like these links to be "nofollow"? Their main reason in there is to be followed... – Krzysiek Dróżdż Apr 12 '19 at 19:06
  • It is this project necessity. – Omniatom Apr 15 '19 at 10:43
0

The only option I see is using {$adjacent}_post_link hook and replacing the fragment of final link or prepare the link yourself from scratch.

Replace:

add_filter( 'next_post_link', 'se334246_nofollow_link', 20, 5);
add_filter( 'previous_post_link', 'se334246_nofollow_link', 20, 5);

function se334246_nofollow_link( $output, $format, $link, $post, $adjacent )
{
    $search = sprintf('rel="%s"', $adjacent);
    $output = str_replace($search, 'rel="nofollow"', $output);
    return $output;
}

From scratch:

add_filter( 'next_post_link', 'se334246_nofollow_link', 20, 5);
add_filter( 'previous_post_link', 'se334246_nofollow_link', 20, 5);

function se334246_nofollow_link( $output, $format, $link, $post, $adjacent )
{
    if ( !$post )
        return $output;

    $title = $post->post_title;
    $title = apply_filters( 'the_title', $title, $post->ID );
    $permalink = get_permalink( $post );

    $inlink = str_replace( '%title', $title, $link );
    $inlink = str_replace( '%date', '', $inlink );

    $inlink = '<a href="' . $permalink . '" rel="nofollow">' . $inlink . '</a>';
    $output = str_replace( '%link', $inlink, $format );

    return $output;
}
1
  • Works great! Thanks a lot man! – Omniatom Apr 15 '19 at 10:48
0

You can filter the markup using the navigation_markup_template filter.

Just make sure the second argument passed, $class, is 'post-navigation' as the _navigation_markup() function (which generates the html) is used by 5 functions in total, each passing a different class.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.