1

I'm creating a newsletter website and each newsletter landing page uses the same template as the front page. Is there anyway to force each newsletter landing page to use the front page template.

Editors can chose the template by template name in the page attributes box when editing a newsletter but I'm wondering if there was a way to make this easier.

Thanks in advance.

4

The solution below if I have understood your question correctly will set the default template to the php page template you wish but you will need to look at what name the file is in your theme files. You state in the title custom post type but in your question have page so I have done this based on page and commented where you can change this to post/custom post.

The solution is to define the default page template and then remove the select template options for non admins to make sure its set you can remove the second hook to allow users to set if it was only making the default be what you wanted.

//  This hooks into the page template and over rides the default template use this to make sure your magazine template is always default
    add_filter( 'template_include', 'default_page_template', 99 );

    function default_page_template( $template ) {
// Change page to post if not a page your working on or custom post type name
        if ( is_singular( 'page' )  ) {
            // change the default-page-template.php to your template name
            $default_template = locate_template( array( 'default-page-template.php' ) );
            if ( '' != $default_template ) {
                return $default_template ;
            }
        }

        return $template;
    }


// removes the user page select meta-box for user roles that are not admins
add_action( 'admin_menu', 'restrict_access' );
function restrict_access() {
// if the user is not admin - you can add any user roles or multiple roles
if(!current_user_can('administrator')){
    // Not tested but think this is the correct code for page template meta-box
    remove_meta_box( 'pageparentdiv', 'page','normal' );
    }
}
  • Thanks for the reply. Yes "newsletter" is a custom post type. – petron Mar 17 '17 at 14:34
2

If your newsletters are a custom post type you can create a template dedicated for it using the template hierarchy.

Template for a single page would be..

single-{custom-post-type-name}.php

Template for an archive page would be..

archive-{custom-post-type-name}.php

These templates get automatically selected you don't need to add them to a page template attribute in the editor.

  • Nice and simple. – Pegues Sep 6 '18 at 12:13

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.