Fahad Sohail
Fahad Sohail

Reputation: 1836

Get 404 page URL in wordpress

It is so strange I cannot find a function in the API to get the link to the 404 page link.

I need to check if a page exists return permalink or return 404 page link.

Am I missing something or am I looking in the wrong places?

Upvotes: 0

Views: 3724

Answers (1)

Spartacus
Spartacus

Reputation: 1508

There isn't a native function, so you'll have to set the 404 yourself:

function wp_404_redirect() {
    global $wp_query;
    $wp_query->set_404();
    status_header( 404 );
    get_template_part( 404 ); 
    exit();
}

Call this function in your else block.

Upvotes: 1

Related Questions