最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - What does the author_nicename parameter do in get_author_posts_url()?

programmeradmin2浏览0评论

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?

Share Improve this question asked Jun 13, 2019 at 9:45 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Say 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.

发布评论

评论列表(0)

  1. 暂无评论