Skip to content

Instantly share code, notes, and snippets.

@goranseric
Forked from davekellam/wordpress_author_url.php
Created October 2, 2019 12:00
Show Gist options
  • Select an option

  • Save goranseric/6fdc3e2acd1ce8a3b2cf2d8413443ed4 to your computer and use it in GitHub Desktop.

Select an option

Save goranseric/6fdc3e2acd1ce8a3b2cf2d8413443ed4 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment