• Resolved YOELO

    (@yoebo)


    I have a function that displays breadcrumb links for pages and the parents. The current page title is displayed as text while the parents are a link. I’d like to have the current page wrapped in H1 tags, is this possible with this code:

    function get_breadcrumb() {
    	global $post;
    	$trail = '';
    	$page_title = get_the_title($post->ID);
    	if($post->post_parent) {
    		$parent_id = $post->post_parent;
    		while ($parent_id) {
    			$page = get_page($parent_id);
    	$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a> » ';
    			$parent_id = $page->post_parent; }
    
    		$breadcrumbs = array_reverse($breadcrumbs);
    		foreach($breadcrumbs as $crumb) $trail .= $crumb; }
    
    	$trail .= $page_title;
    	$trail .= '';
    	return $trail; }

    Or if easier can the current page title/breadcrumb be removed completely only leaving the parents in the list?

    Thanks for any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • anonymized-13749270

    (@anonymized-13749270)

    This might work:

    function get_breadcrumb() {
    	global $post;
    	$trail = '';
    	$page_title = get_the_title($post->ID);
    	if($post->post_parent) {
    		$parent_id = $post->post_parent;
    		while ($parent_id) {
    			$page = get_page($parent_id);
    			$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
    			$parent_id = $page->post_parent;
    		}
    
    		$breadcrumbs = array_reverse($breadcrumbs);
    		foreach($breadcrumbs as $crumb) :
    			$trail .= $crumb;
    			$trail .= $curmb !== end( $breadcrumbs ) ? ' &raquo; ' : '';
    		endif;
    	}
    
    	//$trail .= $page_title; // or just $trail .= "<h1>$page_title<h1>";
    	//$trail .= '';
    	return $trail;
    }
    Thread Starter YOELO

    (@yoebo)

    Thank you Samuel, it works great. I added a slash to the ending <H1> 🙂

    anonymized-13749270

    (@anonymized-13749270)

    Cool!! I didn’t pay attention the the closing tag, great!

    Have a great day 🙂

    Samuel

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to add H1 to this code’ is closed to new replies.