You can do this at an earlier moment by hooking into the right action, like template_redirect
, which fires right before the template will be displayed.
add_action( 'template_redirect', 'wpse14047_template_redirect' );
function wpse14047_template_redirect()
{
if ( is_author() ) {
$id = get_query_var( 'author' );
// get_usernumposts() is deprecated since 3.0
$post_count = count_user_posts( $id );
if ( $post_count <= 0 ) {
//This line could also be wp_redirect
include( STYLESHEETPATH .'/author-redirect.php' );
exit;
}
}
}
Related Posts:
- Load template inside a parent template
- Display a custom 404 page without a redirect
- Submit form to another template (ugly url)
- Page editor missing Templates drop down
- How to edit contents of dynamic_sidebar()?
- I put my blog on a subpage, how do I get page title?
- author.php added to template not working on Nginx server
- Need to give custom page template for each language in WPML
- Templates & CSS – Proper Programming Practice?
- Create Page that uses specific template
- Post formats template
- index.php template is used instead of blog page
- Guest author’s post not display in author template
- Template redirect is_tax() not working
- Hide Front-End Admin Bar Including 32 px Spacing
- What is a good way to present templated content in WordPress?
- Adding variable to get_template_part
- How to apply a custom template for posts by default?
- How to move style from template file to section?
- Subpage template
- How to create a wordpress template without using any page
- Advanced Custom Fields – display when specific template used?
- How do I find the directory of a page template?
- Missing ‘Page Attributes’
- how to use custom page template in a page?
- the_excerpt producing empty output
- Conditionally display different images before the content in a page template
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- Change wp-signup.php Page Template
- How to remove the Template drop down, but keep Parent and Order
- Templates have disappeared from drop down lists
- One of my pages uses the archive.php template only. Why?
- Getting pages filtered by template assigned
- Get link to a specific template file [closed]
- Default Template Selected After Changes in Elementor [closed]
- Use same page template for parent and child pages in a theme
- displaying category and subject posts
- How to duplicate a page template but make minor changes to the header?
- Adding Query to Custom Page Template
- Show different page for first time user
- get_file_data to read data for Custom Template File?
- Page attributes missing
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- wp_enqueue_style and different styles for blog template
- Page template option missing
- How do I get the page template name chosen?
- How can I add text to a specific ‘Edit Page’?
- Custom URL redirect in WP
- get_header(), get_footer() from plugin template
- What template is used for viewing Media Library Files?
- Page template for a site from network
- Author template help. How to check if field exists in the profile?
- Force WordPress to NOT display the manual excerpt
- Undefined get_header function
- Single-page.php template file name not shown
- How to display custom post type?
- Hard Coding Components on a Client Specific Websites
- Will placing custom templates in sub directory break any native WordPress functionality
- Organize template parts and page templates in folders in regards of template hierarchy
- Blog page won’t show Blog template
- templates with page teasers Or Featured Items
- Random home page at each refresh between array of page IDs
- User role templates
- Search button click sends to single-custom_post_type instead staying at the same page
- How can I make custom page templates work on child theme?
- Change Page Template Based on URL Rewrite in WordPress
- Nested Page Template not showing in page attributes
- Creating custom post-listing templates in twentyseventeen child theme
- When to use content-pagename.php?
- Redirect Every Instance of The Author Template Pages to Custom Author Pages
- Using file outside of template hierarchy for Twitter sign in authentication
- Page Templates Used in Custom Post Type
- Problem displaying replies as part of author’s latest comments on author page
- custom template – override plugin template in child theme – issue with scripts
- Is this the best way to complete disable category archive pages?
- Is there a way to share a template/markup with the JSON API so that it doesn’t need to be declared both in PHP and in JS?
- How to install a wordpress website template on an existing website?
- Custom Archive with Content for Custom Post Type
- printf, translation and the_author_posts_link()
- Why is this page using the homepage template and not the one it should?
- Page.php vs Single.php
- My homepage’s width has reduced and I can´t fix it [closed]
- html blog template to wordpress template
- How to prevent random 302 canonical-ish redirect on custom template
- Confused about editing the HTML in a template
- Get_Template_Part and Template files in TwentyTwentyFour Block Editor
- How to duplicate a template in wordpress site editor?
- Styling own template
- WordPress sites translate dynamically generated Homepages
- how bbPress and buddypress add their own page templates to the page template drop down on the page editing screen
- Why is my no-results.php template moving my sidebar and footer into the main container?
- Choose to show or not show title on a template?
- Given a page ID, how to display entire page (header/content/footer/sidebars) from a plugin hook
- changes to templates not showing on server
- Permalink / sub-template issue
- Search results in custom template
- Add multiple pages to theme customizer
- Group pages by custom field values
- Single Post Template with Dropdown Option?
- Using custom post types within a section of a template