1

What i mean is i am trying to add breadcrumbs to my blog and i thought of adding it before content or after title but there's an issue with that - on archive pages or category pages the breadcrumbs appear for every posts.

so i figured i have to attach the breadcrumbs to something above the post - like the head.

how can i do that ?

this is what I've done so far for the content:

add_filter( 'the_content', array($this, 'adding_bread_crumbs') );
function adding_bread_crumbs( $content ) {
    /* Getting the current page permalink and site url */
    $pageURl = preg_replace('/\/$/','',get_permalink());
    $homeURL = preg_replace('/\/$/','',site_url());

    if ( function_exists('yoast_breadcrumb')) {
        /* Checking if the current page is home page */
        if($pageURl != $homeURL && !is_page('Home')){
            $breadcrumbs = '<div class="breadcrumbHolder">';
            $breadcrumbs .= yoast_breadcrumb('<p id="breadcrumbs">','</p>',false);
            $breadcrumbs .= '</div>';
            $content = $breadcrumbs.$content;
        }
    }
    return $content;
}

Is there anything that would replace 'the_content' another hook maybe? or is there an action i have to use ?

Thanks

5
  • 1
    What about adding your own do_action('my_breadcrumbs_hook'); into your theme?
    – birgire
    Commented Dec 27, 2013 at 15:38
  • ok but how will i make sure it comes out after header ?
    – Neta Meta
    Commented Dec 27, 2013 at 15:40
  • well, you can place your own hook anywhere you want, but then it would be smart to do it via child theme just as @s_ha_dum is suggesting. Just add this line where you want <?php do_action('my_breadcrumbs_hook'); ?>
    – birgire
    Commented Dec 27, 2013 at 15:43
  • I see so basically it would be just like placing a call for the above function somewhere in the theme.
    – Neta Meta
    Commented Dec 27, 2013 at 15:44
  • Crap my above question was idiotic.. i will create my own.. and place is after wp_head().. thanks
    – Neta Meta
    Commented Dec 27, 2013 at 15:56

3 Answers 3

4

So far as I am aware, there is no hook in the location you need, if I understand you. The closest I can think of is loop_start, which as you might expect runs when the loop begins. The problem with that hook is that you don't know what content the theme may have between the <head> of the document and the place where the Loop runs.

By far the best solution is to edit the functionality, or your own hook, into your theme if you've written the theme, or create a child theme and edit that if you are using someone else's theme.

1
  • How do i create my own hook ? or edit it's functionality ?
    – Neta Meta
    Commented Dec 27, 2013 at 15:43
0

Inside your theme, wherever you want your output to show up, add the following:

do_action( 'my_sweet_hook' );

Then you'll be able to use add_action( 'my_sweet_hook', 'my_sweet_breadcrumbs' ); (along with the appropriate function code) to display your content there.

0

In WordPress 5.2 there's wp_body_open which is triggered after the opening tag.

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.