bbp_redirect_canonical

Remove the canonical redirect to allow pretty pagination.

Description

(bool|string) bbp_redirect_canonical( (string) $redirect_url ); 

Returns (bool|string)

False if it's a topic/forum and their first page, otherwise the redirect url

Parameters (1)

0. $redirect_url (string)
The redirect url.

Usage

  1. if ( !function_exists( 'bbp_redirect_canonical' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/theme-compat.php'; 
  3.  
  4. // The redirect url. 
  5. $redirect_url = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_redirect_canonical($redirect_url); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/core/theme-compat.php  
  1. function bbp_redirect_canonical( $redirect_url ) { 
  2. global $wp_rewrite; 
  3.  
  4. // Canonical is for the beautiful 
  5. if ( $wp_rewrite->using_permalinks() ) { 
  6.  
  7. // If viewing beyond page 1 of several 
  8. if ( 1 < bbp_get_paged() ) { 
  9.  
  10. // Only on single topics... 
  11. if ( bbp_is_single_topic() ) { 
  12. $redirect_url = false; 
  13.  
  14. // ...and single forums... 
  15. } elseif ( bbp_is_single_forum() ) { 
  16. $redirect_url = false; 
  17.  
  18. // ...and single replies... 
  19. } elseif ( bbp_is_single_reply() ) { 
  20. $redirect_url = false; 
  21.  
  22. // ...and any single anything else... 
  23. // 
  24. // @todo - Find a more accurate way to disable paged canonicals for 
  25. // paged shortcode usage within other posts. 
  26. } elseif ( is_page() || is_singular() ) { 
  27. $redirect_url = false; 
  28.  
  29. // If editing a topic 
  30. } elseif ( bbp_is_topic_edit() ) { 
  31. $redirect_url = false; 
  32.  
  33. // If editing a reply 
  34. } elseif ( bbp_is_reply_edit() ) { 
  35. $redirect_url = false; 
  36.  
  37. return $redirect_url;