Skip to content

Instantly share code, notes, and snippets.

@tatthien tatthien/functions.php

Last active Oct 1, 2019
Embed
What would you like to do?
Redirect pages to 404 with a conditional in WordPress
<?php
function redirect() {
if(true === $something) {
/* @var WP_Query $wp_query */ global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( '404' );
exit();
}
}
add_action( 'template_redirect', 'redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.