admin管理员组文章数量:1431024
When a page request is made, at what point does is_front_page
start working? As I recall, if you try using it too early it will always return false.
My assumption is that the wp
action is the first point that is_front_page
will work, however, the conditional check for is_front_page
is part of the WP_Query
class, so wouldn't parse_query
then be the earliest safe use?
When a page request is made, at what point does is_front_page
start working? As I recall, if you try using it too early it will always return false.
My assumption is that the wp
action is the first point that is_front_page
will work, however, the conditional check for is_front_page
is part of the WP_Query
class, so wouldn't parse_query
then be the earliest safe use?
1 Answer
Reset to default 7The parse_query()
method of the WP_Query
class sets the variables on which the conditional tags are based.
The parse_query
hook are executed before returning from parse_query()
method, variables are already set (eg. is_home
, used by is_front_page()
) and is_front_page()
will work, but function that changes the current state can be hooked to parse_query
(it's still parse_query()
method, which sets variables like is_home
).
Hooks pre_get_posts
is executed directly after parse_query
, that is why it is for me the first safe hook to use conditional tags.
Conditional Tags in Codex
You can only use conditional query tags after the
posts_selection
action hook in WordPress (thewp
action hook is the first one through which you can use these conditionals). For themes, this means the conditional tag will never work properly if you are using it in the body offunctions.php
, i.e. outside of a function.However: if you have a reference to the query object (for example, from within the
parse_query
orpre_get_posts
hooks), you can use the WP_Query conditional methods (eg:$query->is_search()
)
本文标签: actionsWhat is the earliest possible hook for safely using isfrontpage
版权声明:本文标题:actions - What is the earliest possible hook for safely using `is_front_page`? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745569355a2663954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论