1

I have a difficult question. What's the best way to load a different header based on a post format? I guess I could load another loop around the header but I noticed the site does slow down. This is the code on my index.php:

<?php get_header();?>

<section id="block">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; endif; ?>

</section>

<?php get_footer();?>

Thanks

  • What do you need different header ( get_header() ) in single post format ? – user5200704 Apr 27 '16 at 4:28
  • 2
    "what is best?" type of questions are almost never good questions, best for what and when? please edit the question and try to be as specific as possible. For example you talk about a second loop, but don't show it... a second loop if done right in theory should not have any impact on noticeable performance – Mark Kaplun Apr 27 '16 at 5:19
5

Say if your have header-video.php used for video post format.

Replace get_header(); with get_header(get_post_format()); in your regular singular.php or index.php. If WP can find header-video.php it will load it otherwise it will automatically will fallback to header.php.

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.