How to disable template files in single page wordpress theme

I am creating a single page WordPress site and I would like disable/delete/remove all other pages so that they just return a 404.

So if the user tries to go to an archive page or a single post page it does not work. I only want one working page on the entire site.

Related posts

Leave a Reply

2 comments

  1. You can simply force all pages to be redirected to the front page by putting the following code in your functions.php:

    function redirect_to_homepage() {
        if ( ! is_front_page() ) {
            wp_redirect( home_url( '/' ), 302 );
            exit;
        }
    }
    add_action( 'template_redirect', 'redirect_to_homepage' );
    

    Just a quick note: is_front_page() checks if the user is trying to access the page that is set for the front page in Settings > Reading. If no such page is set, use is_home() instead.

    Reference:
    http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
    http://codex.wordpress.org/Function_Reference/is_front_page
    http://codex.wordpress.org/Function_Reference/is_home

  2. Instructions for what I think you want to have done. This will remove all other pages/posts, and make the page you did not delete into the home page of your website.

    1. Log into your site
    2. In the admin panel go to pages
    3. Select all of the pages except the one you want to keep as the home
    4. In the “Bulk Actions” select move to trash and click apply
    5. Go into the trash section of pages
    6. Select all of the pages
    7. In the “Bulk Actions” select move to delete permanently and click apply
    8. Repeat steps 2-7 for the “posts”
    9. Go to the settings reading page in the admin panel
    10. Check off static page
    11. In the front page drop down select the page you did not delete
    12. Click save at the bottom of the page.