Last active
January 31, 2018 07:05
-
-
Save gatespace/d6a7bba8919fc225fc7c4a5b0910dd5b to your computer and use it in GitHub Desktop.
[WordPress] ターム(カテゴリー・タグ)アーカイブで記事が指定件数以下なら404扱いにしたい ref: https://qiita.com/gatespace/items/a29b0814a308fa2d77d7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'template_redirect', 'tag_archive_template_redirect' ); | |
function tag_archive_template_redirect() { | |
if ( ! is_tag() ) { // タグアーカイブ以外は何もしない | |
return; | |
} | |
$queried = get_queried_object(); | |
if ( $queried->count < 6 ) { // 総記事数が5件以下なら | |
global $wp_query; | |
$wp_query->set_404(); | |
status_header( 404 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment