PHP code example of inc2734 / wp-breadcrumbs

1. Go to this page and download the library: Download inc2734/wp-breadcrumbs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inc2734 / wp-breadcrumbs example snippets



$breadcrumbs = new Inc2734\WP_Breadcrumbs\Bootstrap();
$items = $breadcrumbs->get();

/**
 * Filter items
 */
add_filter(
	'inc2734_wp_breadcrumbs',
	function( $items ) {
		// Do something here
		return $items;
	}
);

/**
 * Add link attribute for the last item (default: true)
 */
add_filter( 'inc2734_wp_breadcrumbs_remove_last_link', '__return_false' );

/**
 * Change the taxonomy used in the breadcrumb (default: first taxonomy attached)
 */
add_filter(
	'inc2734_wp_breadcrumbs_main_taxonomy',
	function( $first_post_type_taxonomy, $taxonomies, $post_type_object ) {
		// Logic to set the primary taxonomy of your post type if it has multiple ones
		if ( 'product' === $post_type_object->name ) {
			return 'my_main_product_taxonomy';
		}
		return $first_post_type_taxonomy;
	},
	10,
	3
);

/**
 * If a post (post, CPT, etc.) has more than one term, this filter provides a way to set the main term
 */
add_filter(
	'inc2734_wp_breadcrumbs_main_term',
	function( $main_term, $terms, $taxonomy, $post_id ) {
		// Example with the SEO Framework plugin
		$tsf_main_term = get_post_meta( $post_id, sprintf( '_primary_term_%s', $taxonomy ), true );
		return $tsf_main_term ? get_term( $tsf_main_term ) : $main_term;
	},
	10,
	3
);