I am trying to modify the default author link url structure. In the URL, I would also like to change the string author to operator add some author meta along with the username.
So far, I have successfully changed the string author to operator but I would also like to add the country (author meta) he/she belongs in the url. So the modified url should be like this: example/country-name/operator/newuser
Can someone help me on this?
I am trying to modify the default author link url structure. In the URL, I would also like to change the string author to operator add some author meta along with the username.
So far, I have successfully changed the string author to operator but I would also like to add the country (author meta) he/she belongs in the url. So the modified url should be like this: example/country-name/operator/newuser
Can someone help me on this?
Share Improve this question edited Feb 14, 2019 at 5:47 saurav.rox asked Feb 14, 2019 at 4:54 saurav.roxsaurav.rox 2051 silver badge13 bronze badges1 Answer
Reset to default 0This is just an example / idea and I haven't tested if this really works. But I think it could be something along these lines.
function custom_author_base() {
global $wp_rewrite;
global $wp_query;
// On author pages you get current author for example with $wp_query
$curauth = $wp_query->get_queried_object();
// Get the required data
$country = get_user_meta($curauth->ID, 'country_meta_key', true);
// Turn the country into url friendly format and prepend it to operator
$author_slug = sanitize_title($country) . '/operator';
// Set the custom string as author base
$wp_rewrite->author_base = $author_slug;
}
add_action('init', 'custom_author_base');
This example will propably need some tweaking. You might also need extra functions to handle other cases than the auhtor page where the author page url is shown. E.g. get_author_posts_url
might need some tweaking I guess.
I hope this helps you achieve the result you're looking for. Or perhaps others can build on this and help you find a more complete solution.