Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This one has me stumped.

I have a page named 'Login.' I also have a file uploaded in my theme directory called 'page-login.php'.

If I select a default theme template, page-login.php executes like it should. However, when I use a custom template that I created for modal use, page-login.php does not execute.

This is my custom template:

<?php
 /*
* Template Name: Modal
* Author: Me
* URL: myurl.com
*/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="MSSmartTagsPreventParsing" content="true" />
    <meta http-equiv="Imagetoolbar" content="No" />
    <title>Email A Friend</title>
    <style type="text/css">
        body {font-size:13px;}
    </style>
    <link rel='stylesheet' id='gforms_css-css'  href='<?php bloginfo('url'); ?>/wp-content/plugins/gravityforms/css/forms.css?ver=1.6.2.1.1' type='text/css' media='all' />
    <script type='text/javascript' src='<?php bloginfo('url'); ?>/wp-includes/js/jquery/jquery.js?ver=1.7.1'></script>
    <link rel="stylesheet" href='<?php bloginfo('stylesheet_directory'); ?>/style.css' type="text/css" media="screen" />
</head>
<body class="email">
    <div id="emailForm">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php the_content(); ?>
        <?php endwhile; endif; ?>
        <?php wp_footer(); ?>
    </div>
</body>
</html>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Don't name your custom page template files page-{foobar}.php. Doing so will cause just this conflict with the Template Hierarchy for static pages:

  1. custom template file - The Page Template assigned to the Page. See get_page_templates().
  2. page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php
  3. page-{id}.php - If the page ID is 6, WordPress will look to use page-6.php
  4. page.php
  5. index.php

Which means that, if you assign a custom page template to the page, WordPress will use that, first and always.

Solution:

  1. Rename page-login.php as template-login.php
  2. Add the Template Name: Login Page to template-login.php
  3. Assign the Login Page template to your static page named "Login"
share|improve this answer
1  
Thank you, this was the perfect answer. Not only did you tell me how to fix it, you taught me something very important as well. –  Duplosion Nov 21 '13 at 1:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.