Replace author url with another one (wordpress)
Our company blog has 3 authors, each author has their own website url in their profile settings :
Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/
links for profiles:
http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/
I need to replace the link to the admin page, so if any page has a tag <?php the_author_posts_link(); ?>
and the author is Admin, the link should be http://site.com/company/
instead http://site.com/author/Admin/
.
How can i do this?
a source to share
It looks like the function is the_author_posts_link
just calling get_author_posts_url
to get the link, which passes the link through the filter author_link
before returning it. In your theme, functions.php
you can add something like this (untested):
add_filter ('author_link', 'admin_author_link', 10, 3);
function admin_author_link ($ link, $ author_id, $ author_nicename) {
if ($ author_id == 1) {
$ link = 'http://site.com/company/';
}
return $ link;
} a source to share
I think the least heartburn would be wordpress> the_author_meta .
Ask each user to add their url to their wordpress user profile as you did. Then in your theme functions.php
use the_author_meta('user_url')
. Remember this will repeat the URL. To use it as a variable, use get_the_author_meta('user_url')
.
This is how we did it with twenty ten themes, it's in functions.php
function twentyten_posted_on() {
printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_the_author_meta('user_url'), //changed from get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ),
get_the_author()
)
);
}
a source to share
This url is rewritten with .htaccess, which is possible by manually editing the .htaccess.
But easier for a newbie with a plugin like http://wordpress.org/extend/plugins/redirection/ that seems to do what you need.
a source to share