How can i do something after head like adding a hook for after head but before post

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.

Read More

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

Related posts

3 comments

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

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

Comments are closed.