Skip to content

Instantly share code, notes, and snippets.

@ksuzushima
Created May 7, 2018 06:43
Show Gist options
  • Save ksuzushima/f9eb3efcda33a6f8e3a485b7f4acee83 to your computer and use it in GitHub Desktop.
Save ksuzushima/f9eb3efcda33a6f8e3a485b7f4acee83 to your computer and use it in GitHub Desktop.
Redirect 404 status #wordpress
<?php
/**
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
* @link https://developer.wordpress.org/reference/classes/wp_query/set_404/
*/
function status404() {
if ( is_singular( 'hoge' ) ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
}
}
add_action( 'template_redirect', 'status404' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment