page-name.php doesn’t execute on custom template

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’.

Read More

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>

Related posts

1 comment

  1. 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”

Comments are closed.