1

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?

2

Say that get_author_posts_url(1) return the following URL

https://example.com/author/admin/

Passing the $author_nicename will change this. So get_author_posts_url(1, 'foo') will result in

https://example.com/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.