最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Fixing link rel="next" in Yoast SEO for paginated links

programmeradmin7浏览0评论

I've got a site with yoast seo running, as seen in the source:

<title>Redacted</title>
<meta name="description" content="Redacted" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<link rel="canonical" href="Redacted" />
<link rel="next" href="Redacted/page/2/" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Redacted" />
<meta property="og:description" content="Redacted" />
<meta property="og:url" content="Redacted" />
<meta property="og:site_name" content="Redacted" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@Redacted" />
<!-- / Yoast SEO plugin. -->

However, where I have - it should actually be /index.php/page/2. That's fine, I go to fix it.

However for the life of me I can't work out where it's setting it. It's nowhere to be found in the Yoast plugin tools. I tried searching for the text across all plugins (comes up way too much to be useful).

I tried the yoast online documentation but they mostly talk about how meta tags aren't used any more, and more about what canonical and next do, rather than how or where to set them.

Any advice appreciated on how to remedy this.

I've got a site with yoast seo running, as seen in the source:

<title>Redacted</title>
<meta name="description" content="Redacted" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<link rel="canonical" href="Redacted" />
<link rel="next" href="Redacted/page/2/" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Redacted" />
<meta property="og:description" content="Redacted" />
<meta property="og:url" content="Redacted" />
<meta property="og:site_name" content="Redacted" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@Redacted" />
<!-- / Yoast SEO plugin. -->

However, where I have - it should actually be /index.php/page/2. That's fine, I go to fix it.

However for the life of me I can't work out where it's setting it. It's nowhere to be found in the Yoast plugin tools. I tried searching for the text across all plugins (comes up way too much to be useful).

I tried the yoast online documentation but they mostly talk about how meta tags aren't used any more, and more about what canonical and next do, rather than how or where to set them.

Any advice appreciated on how to remedy this.

Share Improve this question edited Jul 12, 2020 at 13:42 mozboz 2,6281 gold badge12 silver badges23 bronze badges asked Jul 9, 2020 at 5:51 Mark MayoMark Mayo 1052 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1 +50

In the current version of Yoast, this link is rendered by presenters/rel-next-presenter.php, which contains this filter:

    public function present() {
        $output = parent::present();
    
        if ( ! empty( $output ) ) {
          /**
           * Filter: 'wpseo_next_rel_link' - Allow changing link rel output by Yoast SEO.
           *
           * @api string $unsigned The full `<link` element.
           */
          return \apply_filters( 'wpseo_next_rel_link', $output );
        }
    
        return '';
    }

So, I'd suggest correcting this by implementing a filter in e.g. your functions.php, such as:

    add_filter( 'wpseo_next_rel_link', 'custom_change_wpseo_next' );

    function custom_change_wpseo_next( $oldLink ) {

        $new_link = 'https://example/index.php/page/2';
        $link = '<link rel="next" href="'. $new_link .'" />' . PHP_EOL;
        
        return $link;

    }

Does that do it?

发布评论

评论列表(0)

  1. 暂无评论