0

What is the first php file wordpress goes to to determine what page, document or URL to load. I have some PHP I want executed to determine what happens when certain URL's are entered. At the moment it's in the 404.php for want of a better place.

This however is not ideal. The index.php in theme is not referenced so what is?

1 Answer 1

1

It's one of the many pages loaded from wp-settings.php. Anyway, you don't have to go that deep into the core structure and spoil WP's native functionality I think, you can do whatever you prefer in theme functions.php, so you can get a page name just by doing something like this in functions.php:

$pagename = get_query_var('pagename');
if ( !$pagename && $id > 0 ) {
    $post = $wp_query->get_queried_object();
    $pagename = $post->post_name;
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks. by the way, if you want to redirect to any page regarding of the pagename, always be aware that if some header fails in plugin or somewhere else (like redirect header), it is usually caused by left empty spaces in wp.. you can have linebreaks or spaces after or before php tags in functions.php, which causes "headers already sent by" warning and prevents you from redirecting lately

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.