I have this shortcode
[broo_user_badges username=""]
and I have to put username between " " But, username is in URL: /author/peter. So, when page domain/author/peter was loaded, on that page this shortcode should be generated:
[broo_user_badges username="peter"]
I found this
add_shortcode('name', 'get_name');
function get_name() {
return $_GET['name'];
}
here How to get URL param to shortcode? but I do not understand how to use that on my case (/author/peter url structure).
Edit: plugin /
I have this shortcode
[broo_user_badges username=""]
and I have to put username between " " But, username is in URL: /author/peter. So, when page domain/author/peter was loaded, on that page this shortcode should be generated:
[broo_user_badges username="peter"]
I found this
add_shortcode('name', 'get_name');
function get_name() {
return $_GET['name'];
}
here How to get URL param to shortcode? but I do not understand how to use that on my case (/author/peter url structure).
Edit: plugin https://wordpress/plugins/badgearoo/
This should work:
function get_name() {
$url = "http://domain/author/peter";
if (preg_match("/author/", $url )) {
$lastSlash = strrpos( $url, "/");
return substr( $url, $lastSlash, strlen($url));
}
}
This will return everything after the last slash.
Two ways to get author name from url
- Using get_query_var()
// http://example/author/peter
$author_name = get_query_var('author_name'); // peter
- Using get_queried_object()
// http://example/author/peter
$author_info = get_queried_object();
$author_name = $author_info->user_login; // peter
// print_r($author_info); // to see more information about Author
For more information read Custom Author Information