I was looking at get_author_posts_url()
which takes the user id as a param and returns a URL. It has an optional second parameter $author_nicename
.
get_author_posts_url( $author_id, $author_nicename );
What does providing $author_nicename
do exactly?
I was looking at get_author_posts_url()
which takes the user id as a param and returns a URL. It has an optional second parameter $author_nicename
.
get_author_posts_url( $author_id, $author_nicename );
What does providing $author_nicename
do exactly?
1 Answer
Reset to default 2Say that get_author_posts_url(1)
return the following URL
https://example/author/admin/
Passing the $author_nicename
will change this. So get_author_posts_url(1, 'foo')
will result in
https://example/author/foo/
You can also check this in the source code of get_author_posts_url()
.
So what does passing the second argument do? It changes the resulting URL. If you don't provide further mechanisms, this will probably result in invalid URLs.
Why is this provided? No idea.
Ok, so checking this file via Git blame turns out, get_author_posts_url()
was previously called get_author_link()
(this change happened on Aug 30, 2006). get_author_link()
was added on Mar 19, 2004 and required the argument $author_nicename
(though it had a fallback).
Why is this provided? Because in earlier times, you needed to pass the (correct) nicename for this to work.