Joy
(@joyously)
The “page” template is checked before the “author” template.
See https://core.trac.wordpress.org/browser/tags/5.4/src/wp-includes/template-loader.php#L57
At the top of the function, there is do_action( 'template_redirect' );
if you want to hook there, or after all the checks, there is a filter you could use instead: $template = apply_filters( 'template_include', $template );
Thank you, Joy.
The template I managed to fix, but unfortunately WordPress still keeps the “author” in priority.
What I need is to leave the “page” as a priority.
I don’t know which WordPress file I can modify this in (though it’s not ideal).
And I couldn’t find a hook. 🙁
Far from ideal. Do not ever modify core files, it will never end well for you.
Joy showed you the hooks you can use. “template_redirect” to hijack the entire process or “template_include” to override whatever WP wanted to use. Her link lands you in an odd spot because the file had been updated, the former action is currently at line 13 and the latter at line 104 of the same page.
Hello friends. I think I missed the title. I apologize. The moderator can change if necessary.
What I need is to “change the route of the links”. Something like.
I got what I wanted using the code below. I don’t know if it’s ideal, but it worked. The page is given priority when using the link with the slug similar to the author’s nickname.
I don’t want to use the author’s page, because I created the page for him. So the slug is the same. However, before typing / slug I opened the author’s page instead of the page.
add_action( 'init', 'wpse16902_init' );
function wpse16902_init() {
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}
add_filter( 'page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules' );
function wpse16902_collect_page_rewrite_rules( $page_rewrite_rules )
{
$GLOBALS['wpse16902_page_rewrite_rules'] = $page_rewrite_rules;
return array();
}
add_filter( 'rewrite_rules_array', 'wspe16902_prepend_page_rewrite_rules' );
function wspe16902_prepend_page_rewrite_rules( $rewrite_rules )
{
return $GLOBALS['wpse16902_page_rewrite_rules'] + $rewrite_rules;
}
A possible solution would be to disable author.php completely, but without redirection. Disable completely. But I couldn’t do that. All the code I found disables author.php, but redirects it. So it still exists, although it is hidden. Anyway, the code above helped me. I just ask now if it is ideal.
-
This reply was modified 4 years, 4 months ago by wpforever18.
(I was wrong. I wanted to quote “user_nicename” instead of “nickname”)