Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

remove WordPress

  • REFUNDED

to remove the prefix "author" in the permalink of each author page i use this code

add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
global $wpdb;
$author_rewrite = array();
$authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users");
foreach($authors as $author) {
$author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
$author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';
}
return $author_rewrite;
}


add_filter('author_link', 'no_author_base', 1000, 2);
function no_author_base($link, $author_id) {
$link_base = trailingslashit(get_option('home'));
$link = preg_replace("|^{$link_base}author/|", '', $link);
return $link_base . $link;
}


now i need to apply the template author.php on my new url

<strong>18h03, EDIT :</strong>
thanx guys but i have find my mystake.
Just i need to change return $link_base . $link; in my code by return $link;

Answers (3)

2012-12-31

phppoet answers:

If i m understanding your question correctly , you want to use firstname lastname fields in place of author prefix.

well you can do this in easy way . just replace few lines of author.php


just like

replace
if ( get_the_author_meta( 'description' ) ) : ?>
<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 60 ) ); ?>
<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
<p><?php the_author_meta( 'description' ); ?></p>


with

if ( is_user_logged_in() ) {


$userid=get_current_user_id();
$user_info = get_userdata($userid);
$username = $user_info->user_login;
$first_name = $user_info-> user_firstname;
$last_name = $user_info-> user_lastname;
$blog_name=get_bloginfo();

<?php
global $userdata;
echo"$first_name"; ?>
<?php echo"$last_name"; ?>
<?php echo"$blog_name" ?>

}


Sébastien | French WordpressDesigner comments:

you don't understand my problem but thanks.
I have find the solution. See my edit.

Thank you.

2012-12-31

Giri answers:

I don't think you need all those codes to remove your author base.

Just go to your root folder, edit .htaccess file and add this code


RewriteRule ^/(.*) /author/$1 [L]


Sébastien | French WordpressDesigner comments:

I have find the solution. See my edit.

Thank you.

2012-12-31

Arnav Joy answers:

where you are directed now using above code?

because i think you can still access author.php , it will just remove author from the url


Sébastien | French WordpressDesigner comments:

Yes in fact there is no problem, just a mistake in my code
I have find the solution. See my edit.

Thank you very much.