Use the hook template_redirect
instead – this will ensure it only runs on the front-end of your site, and not for the admin, login, registration or signup pages.
function wpse_159552_maintenance() {
if ( ! is_front_page() ) {
wp_redirect( home_url() );
exit;
}
include 'maintenance/index.html';
exit;
}
add_action( 'template_redirect', 'wpse_159552_maintenance' );
Related Posts:
- WordPress website keeps loading the maintenance page
- Making an under maintenance page (without using plugins)
- How to redirect to post if search results only returns one post
- How to override admin-bar style
- Masking logout URL
- Logout/login redirect CSS issue
- wp_get_attachment_image returns different image size
- Passing variables to templates (alternatives to globalizing variables)
- Load post with a different template?
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to customize search result page title?
- redirect wp-login.php to another page
- How to fix a theme with page.php Default Template that accidentally deleted?
- WordPress Change Post Templates,but not drop down, but Image selection
- How do I redirect upon login a specific user based on role?
- Using locate-template & shortcodes doesn’t appear to work
- Can I use require() function in a template file?
- How to set global variables in template page?
- Why isn’t is_page_template() adding a body class?
- Query children and parent title
- Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]
- Make “sidebar template” the default template for new pages
- Retrieve post modified date for specific post by post ID
- Attach parent category template to all subcategories
- Add class or ID to any WordPress function
- How to remove howdy dropdown menu content
- How to include local menu based on page id?
- How to create function from code?
- How to extract the variables out from “add_shortcode” function?
- Default Gallery Edit/Template Editable?
- Redirect specific page in WordPress for first time visit
- How to enable template page only for a post id page
- How do I redirect all 404 error url to Subcategory url
- Retrieve tags data in post body
- Stuck on maintenance mode
- How to Display Frontend CSS for Administrator only
- 404 redirect to previous category
- Login Redirect if Logged in from Specific Page
- Functions For Calling Specific Elements
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- Full page template function
- Incorrect redirect after commenting
- wordpress use single ajax in place of multiple ajax requests in a smarter way
- Add Element as a Filter to the_content
- I have problems with loading javascripts
- Pass variable from action back to template
- Need print logo without any ID & class
- How i can put $_GET codes in function.php?
- Define PHP variable from a seperate API if statement
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- Best way to handle lack of titles in microblogging
- attachment page template? only show attachments for current post?
- Run a jquery script on on a certain template page
- Page get parameter doesn’t work with is_single() function
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Contact Form 7 If Condition
- How to include any template using Shortcode fuction?
- Image loading function not working on archive.php template
- Redirect to other page if login
- Add a field into a shortcode of an extension
- How to add array [closed]
- Specify multiple categories for custom post template – FATAL ERROR
- Using functions.php to include code that’s processed inline
- How to make a new function that includes a template
- Redirects based on a JSON file
- Show admin page, only if function is being used
- Overwriting TwentyTwelve template file with child theme template, but lower in the hierarchy
- Prevent creating multiple image resizes in twentytwelve template
- template_redirect action only firing if logged in
- Simplest Way to Build Custom Archives Page?
- Display ACF category image on archive and single template files
- How to redirect Subscribers on login to specific page, when logging in from a Page
- How to require a config file in a template and in function.php?
- the_date() and the_time() functions display actual date an time instead of published date and time
- Load templates, pass arguments, and render output from functions.php
- Redirect to one of two pages after data submitted, depending on the current url
- Changing the HTML of notices in WooCommerce [closed]
- Wildcard 301 Redirect Using Theme Function
- Competing Login Redirects – Need to be Combined?
- Postback redirect through add_action is not triggered
- Restrict access if logged out except for homepage
- WP Enqueue Script Error
- WordPress function with attribute pass to template
- Custom download page
- Javascript and Stylesheet in child page
- Newest comments first not working
- Retrieve a custom form field modified by a filter
- How to create a function to redirect a specified page to another page
- us states dropdown function and echo in theme template files
- How to pass a variable from a template page to the child theme functions.php
- Function the_content
- Shortcode to output get_header not working
- How to request login for user but not for bots
- How can i hide content if not friend in Buddypress? [closed]
- Which template file to edit to edit homepage in Mystile [closed]
- Make a PHP file with a function
- Creating mixture of shortcodes to use in the visual/text editor
- Template Redirect Function Only Working When Logged In
- How to store page-{id}.php templates in custom folder
- Disable Attachment Page Except for Category