0

On single custom post types using the single-course.php template I want a different breadcrumb option to happen, but it's not obeying the && operator in the if statement:

<?php if ( function_exists('yoast_breadcrumb') && !is_page_template( 'single-course.php' ) ) {
    yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} else { ?>
    <p id="breadcrumbs"><span xmlns:v="http://rdf.data-vocabulary.org/#"><span typeof="v:Breadcrumb"><a href="<?php echo site_url(); ?>" rel="v:url" property="v:title">Home</a> » <span rel="v:child" typeof="v:Breadcrumb"><a href="<?php echo site_url('/tracks'); ?>" rel="v:url" property="v:title">Tracks</a> » <strong class="breadcrumb_last"><?php echo get_the_title(); ?></strong></span></span></span></p>
<?php } ?>

This is a template piece that is called in the single-course.php template (and others) after the loop:

    <main class="main" role="main">
        <?php while (have_posts()) : the_post(); ?>
            <?php get_template_part('templates/page', 'header'); ?>

Thanks for any assistance.

  • is_page() && !is_page_template( 'single-course.php' ) ? – Samuel Elh May 10 '15 at 1:21
  • thanks, that worked: used this if ( function_exists('yoast_breadcrumb') && is_page() && !is_page_template( 'single-course.php' ) ) – tigre May 10 '15 at 1:57
2

You need to include is_page() in your if statement :

<?php if ( function_exists('yoast_breadcrumb') && is_page() && !is_page_template( 'single-course.php' ) ) {
    yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} else { ?>
    <p id="breadcrumbs"><span xmlns:v="http://rdf.data-vocabulary.org/#"><span typeof="v:Breadcrumb"><a href="<?php echo site_url(); ?>" rel="v:url" property="v:title">Home</a> » <span rel="v:child" typeof="v:Breadcrumb"><a href="<?php echo site_url('/tracks'); ?>" rel="v:url" property="v:title">Tracks</a> » <strong class="breadcrumb_last"><?php echo get_the_title(); ?></strong></span></span></span></p>
<?php } ?>
1

On single custom post types using the single-course.php template I want a different breadcrumb option to happen

is_page_template will not work on non-pages. If you're looking to tell if you're on a single custom post type page, you should use is_singular and pass in the custom post type name:

if (function_exists('yoast_breadcrumb') && !is_singular('course')) {
  // ...
} else {
  // ...
}

On important note here: if yoast_breadcrumb doesn't exist you will get your alternative breadcrumbs on every page, not just on singular course pages.

  • sounds like that would work but doesn't. tried both is_singular and is_single options. if ( function_exists('yoast_breadcrumb') && !is_singular( 'single-course.php' ) ) { – tigre May 10 '15 at 15:28

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.