Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #399648

    Hi there,

    I’ve a question about the breadcrumbs for a custom post type. I would like to add a page inside the breadcrumb trail for a custom post type. Now it shows like this:

    Home / Custom Post Type Title

    I would like it to be:

    Home / Page / Custom Post Type Title

    I’ve set the page id as the post_parent of the custom post types. Also, I’ve an option variable with the page id, which I could use as well.

    I added this to the class-breadcrumbs.php and it works:

    		if($post_type == 'MY_CUSTOM_POST_TYPE')
    		{
    			$page_id = get_option('MY_CUSTOM_POST_TYPE_PAGE');
    			$trail[] = '<a href="' . get_permalink($page_id) . '">' . get_the_title($page_id) . '</a>';
    		}

    But, I don’t like to change the core fields of the theme, which will be changed when updating the theme. Is it possible to add this in another way, maybe by function or by the post_parent which I’ve set as well?

    Hope you can help!

    #400019

    Hi Tim!

    Thank you for using Enfold.

    Use the breadcrumb filter:

    add_filter('avia_breadcrumbs_trail', 'avia_change_breadcrumb', 20, 1);
    function avia_change_breadcrumb($trail) {
             if(is_singular('custom post type here'))
             {			
    			$home = avia_get_option('frontpage');
    			$last = array_pop($trail);
    			$page_id = get_option('MY_CUSTOM_POST_TYPE_PAGE');
    			$page = '<a href="' . get_permalink($page_id) . '">' . get_the_title($page_id) . '</a>';
    			$trail = array(0 => $home, 1 => $page, 'trail_end' => $last);
             }
             return $trail;
    }

    Adjust the code a bit.

    Cheers!
    Ismael

    #400089

    Thanks Ismael!

    That was exactly what I was looking for. It works great.

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

The topic ‘Breadcrumbs for custom post type’ is closed to new replies.