• 2 questions:

    1. If a searched tag does not exist, does it even step into tag.php file?
    Eg: example.com/tag/ddddddddddddddddddddddddddd/ where the d’s dont exist.

    2. if tag.php does get executed, can somebody tell me why is it hitting a 404 for me (for invalid tag, otherwise works fine)?

    please and thanks in advance.

    code:

    if ( is_tag() && !is_home() ) {
    	$tagterm = single_tag_title( '', false );
    	if ( term_exists( $tagterm ) ) {
    		if ( have_posts() ) :
    			echo "<h2>Keyword Results for ".$tagterm."</h2>";
    		else :
    			echo "<h2>No Entries Found for Keyword ".get_search_query()."</h2>";
    		endif;
    	} else {
    		echo "<h2>No Keyword Match Found for ".get_search_query()."</h2>";
    		wp_tag_cloud( 'taxonomy' => 'post_tag' );
    	}
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, if tag is not found – tag.php is not loaded but instead WP redirects to 404 template.

    You can put your code in 404 template but use check
    if ( get_query_var('tag') ) {
    to show custom message.

    That will work only for tags. I guess there could be found some better solution that would work for all taxonomies (maybe some plugins can handle that).

    Thread Starter shadez

    (@shadez)

    Thanks for your reply. i feel all’s fair with WP for not passing the handle to tag.php file for invalid URL.. most people wont have a code to handle it there. but i think there should be a way with hooks in functions.php as well.. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘404 if Tag does not exist’ is closed to new replies.