Skip to content

Instantly share code, notes, and snippets.

@davekellam
Last active October 2, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davekellam/5890210 to your computer and use it in GitHub Desktop.
Save davekellam/5890210 to your computer and use it in GitHub Desktop.
Remove the WordPress front matter slug from the author url.
<?php
/**
* Modify Author links go to the right page
*/
function dk_author_link( $link, $author_id ) {
$link = str_replace( 'FRONT_URL_PATH/', '', $link );
return $link;
}
add_filter( 'author_link', 'dk_author_link', 10, 2 );
/**
* Custom rewrite rules to make sure Author links go to the right page
*/
function dk_author_url( $author_rules ) {
foreach ($author_rules as $old_key => $val) {
$new_key = str_replace( 'FRONT_URL_PATH/', '', $old_key );
$author_rules[$new_key] = $val;
unset( $author_rules[$old_key] );
}
return $author_rules;
}
add_filter( 'author_rewrite_rules', 'dk_author_url' );
@henrywright
Copy link

Hi Dave,

Does this remove the author base from author links? For example, does example.com/author/username become example.com/username?

@davekellam
Copy link
Author

Didn't realize there was a comment here. Haven't tested it, but I imagine putting author/ instead of FRONT_URL_PATH/ would work. That said, there may be weird knock-on effects if you completely get rid of that front part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment