If you click any link that doesn't exist in my main site site, for example this link, i expect the WordPress to use the default index.php file that has this loop inside it:

<div class="main col <?php post_class(); ?>">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <?php $post_id = get_the_ID(); ?>
        <?php get_template_part('content',get_post_format()); ?>
    <div class="main col">
        <?php comments_template(); ?>
        <?php endwhile; ?>
        <?php else: ?>
    <div class="main col">
        <?php get_template_part('content', 'none'); ?>
        <?php endif; ?>

So i expect WordPress to load the content-none.php file, but it doesn't.

What does this mean? Am I missing any logic that is required to do something that when no real link/page exist do this?


The conditional you use to output get_template_part('content', 'none'); is only triggered if there is no post in the main loop, for example, when a category has no posts in it:

if (have_posts()){
    while(have_posts()) {
        // If the category has a post and we are on a category page, then show the posts
        get_template_part('content', 'archive');
} else {
    //If the category has no posts, display a message that no post exists
    get_template_part('content', 'none');

But this only happens when you visit www.example.com/category/some-cat/, and the /some-cat/ is actually an existing category slug. If you try to access a page that doesn't exist, the 404.php template will be used instead.

  • 1
    ahhhh That means I am missing to create a 404 error page? Right? May be like this → codex.wordpress.org/Creating_an_Error_404_Page – The WP Intermediate Jun 7 '17 at 11:20
  • @TheWPNovice Yes, exactly. I added more details to the answer. – Jack Johansson Jun 7 '17 at 11:21
  • Got it sir. I will create one. I have to wait fro another 7 minutes to accept the answer. I am trying to accept system says wait for another 7 minutes. – The WP Intermediate Jun 7 '17 at 11:22
  • @TheWPNovice That's alright. You should always try the answer and accept it ONLY if it solves your problem, whether directly or indirectly. By the way you can see the page title is Page Not Found which indicates you re on a 404 page, but there is no template to display. – Jack Johansson Jun 7 '17 at 11:23
  • 1
    @TheWPNovice It's a file named 404.php, located in the templates root folder. I suggest you visit and bookmark this website, this will greatly help to understand how templates work. – Jack Johansson Jun 7 '17 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.