WordPress tip: Restrict user access to specific templates

Simply create a new page template and paste the following at the very beginning of the file:

<?php
/* Template Name: Restricted to Authors only */

if ( !current_user_can('author')) {
	wp_die('You don’t have access to this page.')
}
?>

Thanks to Kevin Chard for this snippet!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress tip: Restrict user access to specific templates

Leave a Reply

Your email address will not be published. Required fields are marked *