I really appreciated the solution for the author rewrite rules here: Change Author Base Slug for different Roles

The solution worked for me, however, when I now use the get_author_posts_url($id) method to get the author link url, it provides a link without the slug such as www.mysite.com//username -- if i type in the correct url into my browser www.mysite.com/slug/username it works and pulls up my author template. I'm trying to get the author post URL generated from WP to be correct.

Any idea the get_author_posts_url method is returning the URL with a blank slug?

Here's the code I did for modifying the author URLs:

$sds_author_levels = array( 'fans' );

add_action( 'init', 'sds_user_init' );
function sds_user_init()
 global $wp_rewrite;
 $author_levels = $GLOBALS['sds_author_levels'];

 // Define the tag and use it in the rewrite rule
 add_rewrite_tag( '%author_level%', '(' . implode( '|', $author_levels ) . ')' );
 $wp_rewrite->author_base = '%author_level%';

add_filter( 'author_link', 'sds_author_link', 10, 2 );
function sds_author_link( $link, $author_id )
  $author_level = 'fans';
  $link = str_replace( '%author_level%', $author_levels, $link );
  return $link;

So when I use the get_author_posts_url($id) method, it returns www.mysite.com//username rather than www.mysite.com/fans/username

Any idea why the "fans" slug isn't being included?

  • 1
    what does your author_link filter function look like? – Milo Mar 7 '14 at 1:08
  • I edited the question to include the code such as the author_link filter function. – RailsTweeter Mar 7 '14 at 13:12

Your Answer

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

Browse other questions tagged or ask your own question.