Skip to:

Opened 7 years ago

Closed 6 years ago

#4981 closed enhancement (fixed)

Regenarate url's in Rel Next/Prev According buddypress pages

Reported by: megainfo Owned by: r-a-y
Milestone: 2.1 Priority: normal
Severity: minor Version: 1.7
Component: Core Keywords: has-patch commit


In all Byuddypress pages, the rel='next' and rel='prev' are generated by wordpress.

it would be interesting to regenarate them according the current buddypress page.

Attachments (1)

4981.01.patch (1004 bytes) - added by r-a-y 6 years ago.

Download all attachments as: .zip

Change History (14)

#1 @r-a-y
7 years ago

Here's some documentation on prev / next:

I think this issue becomes more prevalent with BP 1.7 due to the theme compat layer.

However, in order to generate these links we'd need to query for them.

For example, if I'm on an activity permalink page, we'd need to query for the previous and next activity item for that user.

It's a big job for little gain.

My opinion is we should remove these prev / next links when on a BuddyPress page.

#2 @boonebgorges
7 years ago

My opinion is we should remove these prev / next links when on a BuddyPress page.

For most BP activity types (groups, users, etc), the concept of "previous" and "next" items doesn't really make sense anyway. So IMO it definitely makes sense to remove them in these cases. For activity permalinks, it does make sense to have such links (I suppose), but r-a-y is right that it may be a lot of work for a marginal benefit. So, until someone's taken the time to implement it, maybe it makes sense to remove them here too.

Is there a theme-independent way to remove the links? (too lazy to look)

#3 @r-a-y
7 years ago

  • Milestone changed from Awaiting Review to 1.8
  • Version set to 1.7

Is there a theme-independent way to remove the links? (too lazy to look)

Yup, they are basically hooked into 'wp_head'. If we are to remove them, should this code go into the BP_Legacy class? I think that's the most logical place for this.

Tentatively moving to 1.8.

#4 @megainfo
7 years ago

Hi @boonebgorges, @r-a-y

Im agree with you @boonebgorges to remove these prev / next links when on a BuddyPress page. By adding this code somewhere in buddypress core.

function _bp_maybe_remove_adjacent_posts_rel_link_wp_head() {
  if ( ! bp_is_blog_page() && ! is_404() ) {
  	remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
  	add_action( 'bp_head', 'bp_adjacent_rel_link_wp_head' , 1);
add_action( 'wp_head', '_bp_maybe_remove_adjacent_posts_rel_link_wp_head' , 1 );

But I suggest adding rel="next" and rel="prev" in pagination in all buddypress components (members, groups, activity, messages,...etc).

Check this video that talk about SEO and Pagination :

This can be done by adding a filter to paginate_links wp function :

add_filter('paginate_links', 'bp_add_rel_next_prev_paginate_links',10 , 1 );
function bp_add_rel_next_prev_paginate_links( $pag_links ) {
	$pag_links = str_replace( '<a class="prev ', '<a rel="prev" class="prev ', $pag_links );
	$pag_links = str_replace( '<a class="next ', '<a rel="next" class="next ', $pag_links );

	return $pag_links;

#5 @boonebgorges
7 years ago

megainfo - Thanks for the first function. At a glance, that seems reasonable.

As for the second idea, I like the thought of including rel="prev" etc, but there must be a better way to do it than doing a str_replace(). I don't have time to research it in detail at the moment, but isn't there a way to tell paginate_links() to include these attributes? If not, shouldn't we be offering an upstream patch, since this would make sense for WP too?

#6 @megainfo
7 years ago

There is any filter in paginate_links() to include these attributs, i think it time to suggest in wordpress to add a filter or a rel attribut to the href with next and prev class.

Version 0, edited 7 years ago by megainfo (next)

#7 @megainfo
7 years ago

I forget to suggest adding rel="next" to "load more" href in bp default and compact theme.

#8 @boonebgorges
7 years ago

i think we need to suggest to wordpress team to add a filter (or a rel="next" rel="prev" attribut to the href with next and prev class).

Yes. If you open a ticket, please link to it from this thread.

#9 @megainfo
7 years ago

I was open a ticket in wordpress trac

#10 @boonebgorges
7 years ago

  • Milestone changed from 1.8 to Future Release

#11 @r-a-y
6 years ago

  • Component changed from All Components to Core
  • Keywords has-patch added
  • Milestone changed from Future Release to 2.1

Attached patch removes the relational "prev" and "next" links when on a BuddyPress page.

I decided to put this in core since two DB queries are run when WP decides to fetch these links. And we hate additional queries ;)

Last edited 6 years ago by r-a-y (previous) (diff)

6 years ago

#12 @DJPaul
6 years ago

  • Keywords commit added

Looks good

#13 @r-a-y
6 years ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 8511:

Remove "prev" and "next" links when on a BuddyPress page.

WordPress injects these links in the <head> of each WordPress post.
However, BuddyPress doesn't adhere to these links. These links also take
two DB queries on each page load and are uncached.

Therefore, this commit removes these links.

Fixes #4981.

Note: See TracTickets for help on using tickets.