I have a custom post type (that I'm using on a template page), the custom post type is called 'headerhome'. When I post say a gallery there I'm trying to get it to redirect to 'single-headerhome.php', yet it always just goes to 'single.php'.

The name of the custom post type itself is arbitrary, the name of the templage page it's on is 'front-page.php'.

I'm really confused, I'm not the best at WP yet so when something simple like this doesn't work I have no idea how to fix it, even after pouring over the codex for an hour.

// Add new post type for homepage
add_action('init', 'frontpage_top_init');
function frontpage_top_init() 
    $args = array(
        'label' => __('Homepage'),
        'singular_label' => __('Homepage'),
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 5,
        'supports' => array('title','editor'),
        'has_archive' => true


Here's my code on the front-page.php


    Template Name: frontpage
<?php get_header(); ?>
<div id="main-content">
<div class="head-home">
$portfolio_query = new WP_Query(array(
        'post_type' => 'headerhome',
        'showposts' => 1
        ) );
      <?php while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?>

       <h2><?php the_title(); ?></h2>  
      <?php the_content(); ?>

  <div style="clear:both"></div>

  <div class="embed-container">
      <?php the_field('showreel'); ?>

  </div> <!-- end div embed-container -->   

    </div> <!-- end div head-home -->               

    <div class="gallerydescription">
        <?php the_field ('gallery-description'); ?>
    </div> <!-- end div gallerydescription -->  

<?php the_field('image-1'); ?>
<div style="clear:both;"></div>

<?php endwhile; wp_reset_postdata();?>

</div> <!-- end div main-content -->

<?php get_footer(); ?>

No matter what I try, it always uses single.php and not single-headerhome.php. If my understand of wordpress is correct, and it's probably not - shouldn't creating the template file single-headerhome.php automatically make wordpress use that for this post type?

1 Answer 1


Have you flushed your permalinks?

If not, visit your permalinks page in your dashboard, then, refresh the page you are trying to view.

Let us know if that helps.


Upon re-reading your question, actually, no - just because you create a single-post_type.php file does not mean WordPress will use that file with regards to your front-page.php template file.

Your front-page.php file is what is rendering your post. This is your issue.

If you want your single-post_type.php file to render the display of your post type within front-page.php then you can do the following;

$portfolio_query = new WP_Query(array(
'post_type' => 'headerhome',
'showposts' => 1

<?php while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?>

<?php get_template_part('single-post_type.php'); ?>
<?php endwhile; wp_reset_postdata();?>

But obviously make sure that single-post_type.php does not contain a loop/query within itself for if it does then you should remove the outer while/endwhile statements contained within front-page.php

  • Yeah I've flushed my permalinks. Well no, I want front-page.php to render my post, I just want single-headerhome.php to be used when a gallery image or something is clicked on. Currently it uses the single.php. Or maybe I've misunderstood you, I'm sort of new to wordpress!
    – andy
    Nov 4, 2012 at 11:03
  • Ok so it seems to be a little unclear here. front-page.php will handle what you see on the front page, when you click through to a single post type link, the single-post_type.php will come into effect. I'm stating the obvious I know, but I'm trying to understand the relevance of your front-page.php in this issue when you seem to be talking about being on a single page (after someone has clicked a link). i.e. domain.com/my-post-type-permalink instead of domain.com
    – Adam
    Nov 4, 2012 at 11:19
  • Well the fact I mentioned front-page.php was just incidental so people knew I was using a template page for the custom post type. www.scottomahony.co.uk is the site. It's just a simple site I'm making for a friend. However single-post_type.php is NOT working, that's the problem. It's always using single.php when I click through on images etc. That's what I'd like to fix, i'd like it to use single-post_type.php, or single-headerhome.php as it's called.
    – andy
    Nov 4, 2012 at 11:37
  • What is the "portfolio" parameter in your permalink represent /post_type/portfolio/%postname% ? Is that a category? Taxonomy?
    – Adam
    Nov 4, 2012 at 11:42
  • 1
    The issue here is that you are querying your custom post type which contains 1 post with an embedded gallery of image-attachments. The images themselves are linking to the individual attachment pages. You can see this when you go into the custom post type POST edit screen and click on the media library icon, then the GALLERY tab. You will see 3 buttons that allow you to link directly tot he image (FILE), to the attachment page (CURRENTLY selected) or nothing at all. That's your problem. When you click on the image, you are seeing single.php because WP is looking for attachment.php first!
    – Adam
    Nov 4, 2012 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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