shortcode_name = 'adminz_breadcrumb';
$___->shortcode_title = 'Breadcrumb';
$___->shortcode_icon = 'text';
$___->options = function () {
$_options = [];
// $other_plugins = [
// 'type'=> 'select',
// 'heading' => 'Use Integrations plugin',
// 'default' => '',
// 'options' => [
// '' => ADMINZ_NAME,
// ],
// ];
// if ( class_exists( 'WPSEO_Admin_Init' ) ) {
// $other_plugins['options']['wpseo'] = 'Yoast SEO';
// }
// if ( class_exists( 'RankMath' ) ) {
// $other_plugins['options']['rankmath'] = 'RankMath';
// }
// $_options['integrations'] = $other_plugins;
$_options['seperator'] = array(
'type' => 'textfield',
'heading' => 'Seperator',
'default' => '/',
// 'conditions' => 'integrations == ""',
);
$_options['hide_current_item'] = array(
'type' => 'checkbox',
'heading' => 'Hide current_item',
'default' => '',
// 'conditions' => 'integrations == ""',
);
$_options['post_title_options'] = array(
'type' => 'group',
'heading' => __('Title'),
'options' => array(
'size' => array(
'type' => 'select',
'heading' => 'Font Size',
'default' => '',
'options' => require(get_template_directory() . '/inc/builder/shortcodes/values/sizes.php')
),
'style' => array(
'type' => 'radio-buttons',
'heading' => 'Font Style',
'default' => 'uppercase',
'options' => array(
'normal' => array('title' => 'Abc'),
'uppercase' => array('title' => 'ABC'),
),
),
),
);
$_options['advanced_options'] = require(get_template_directory() . '/inc/builder/shortcodes/commons/advanced.php');
return $_options;
};
$___->shortcode_callback = function ($atts, $content = null) {
// make sure load 1 time
if (
isset($GLOBALS['administrator-z']['breadcrumb_exist']) &&
$GLOBALS['administrator-z']['breadcrumb_exist'] === true
) {
return '';
}
$GLOBALS['administrator-z']['breadcrumb_exist'] = true;
extract(shortcode_atts(array(
'_id' => "admz_" . rand(),
'seperator' => '/',
'hide_current_item' => '',
'style' => 'normal',
'size' => '',
'class' => 'adminz_breadcrumb',
'visibility' => '',
// 'integrations'=>''
), $atts));
if (class_exists('RankMath')) {
return do_shortcode('[rank_math_breadcrumb] ');
}
if (class_exists('WPSEO_Admin_Init')) {
return do_shortcode('[wpseo_breadcrumb]');
}
ob_start();
// Define
global $post;
$custom_taxonomy = apply_filters('adminz_breadcrumb_custom_taxonomy', ''); // If you have custom taxonomy place it here
$classes = 'breadcrumbs';
if ($style) {
$classes .= " " . $style;
}
if ($size) {
$classes .= " is-" . $size;
}
if ($class) {
$classes .= " " . $class;
}
if ($visibility) {
$classes .= " " . $visibility;
}
$defaults = array(
'seperator' => $seperator,
'id' => $_id,
'classes' => $classes,
'home_title' => get_the_title(get_option('page_on_front')),
);
$sep = '
' . esc_html($defaults['seperator']) . '';
$position = 1;
// Start the breadcrumb with a link to your homepage
echo '';
echo '
';
do_action('adminz_breadcrumb_before_items');
// Creating home link
echo '- ' . esc_html($defaults['home_title']) . '
' . apply_filters('the_title', $sep);
$position++;
if (is_single()) {
// Get posts type
$post_type = get_post_type();
// If post type is not post
if ($post_type != 'post') {
$post_type_object = get_post_type_object($post_type);
$post_type_link = get_post_type_archive_link($post_type);
if ($post_type_object) {
echo '- ' . do_shortcode($post_type_object->labels->name) . '
' . apply_filters('the_title', $sep);
}
$position++;
}
// Get categories
$category = get_the_category($post->ID);
// If category not empty
if (!empty($category)) {
// Arrange category parent to child
$category_values = array_values($category);
$get_last_category = end($category_values);
// $get_last_category= $category[count($category) - 1];
$get_parent_category = rtrim(get_category_parents($get_last_category->term_id, true, '+'), '+');
$cat_parent = explode('+', $get_parent_category);
// Store category in $display_category
$display_category = '';
foreach ($cat_parent as $p) {
preg_match('#(.*)#', $p, $matches);
$display_category .= '- ' . $matches[2] . '
' . $sep;
$position++;
}
}
// If it's a custom post type within a custom taxonomy
$taxonomy_exists = taxonomy_exists($custom_taxonomy);
if (empty($get_last_category) && !empty($custom_taxonomy) && $taxonomy_exists) {
$taxonomy_terms = get_the_terms($post->ID, $custom_taxonomy);
$cat_id = $taxonomy_terms[0]->term_id;
$cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy);
$cat_name = $taxonomy_terms[0]->name;
}
// Check if the post is in a category
if (!empty($get_last_category)) {
echo do_shortcode($display_category);
echo '- ' . get_the_title() . '
';
$position++;
} else if (!empty($cat_id)) {
echo '- ' . do_shortcode($cat_name) . '
' . apply_filters('the_title', $sep);
$position++;
echo '- ' . get_the_title() . '
';
$position++;
} else {
echo '- ' . get_the_title() . '
';
$position++;
}
} else if (is_archive()) {
if (is_tax()) {
// Get posts type
$post_type = get_post_type();
// If post type is not post
if ($post_type != 'post') {
$post_type_object = get_post_type_object($post_type);
$post_type_link = get_post_type_archive_link($post_type);
if ($post_type_object) {
echo '- ' . do_shortcode($post_type_object->labels->name) . '
' . apply_filters('the_title', $sep);
}
$position++;
}
$custom_tax_name = get_queried_object()->name;
echo '- ' . do_shortcode($custom_tax_name) . '
';
$position++;
} else if (is_category()) {
$parent = get_queried_object()->category_parent;
if ($parent !== 0) {
$parent_category = get_category($parent);
$category_link = get_category_link($parent);
if ($parent_category) {
echo '- ' . do_shortcode($parent_category->name) . '
' . apply_filters('the_title', $sep);
}
$position++;
}
echo '- ' . single_cat_title('', false) . '
';
$position++;
} else if (is_tag()) {
// Get tag information
// $term_id = get_query_var('tag_id');
// $taxonomy = 'post_tag';
// $args = 'include=' . $term_id;
// $terms = get_terms($taxonomy, $args);
// $get_term_name = $terms[0]->name;
$get_term_name = get_queried_object()->name;
// Display the tag name
echo '- ' . do_shortcode($get_term_name) . '
';
$position++;
} else if (is_day()) {
// Day archive
// Year link
echo '- ' . get_the_time('Y') . ' Archives
' . apply_filters('the_title', $sep);
$position++;
// Month link
echo '- ' . get_the_time('M') . ' Archives
' . apply_filters('the_title', $sep);
$position++;
// Day display
echo '- ' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives
';
$position++;
} else if (is_month()) {
// Month archive
// Year link
echo '- ' . get_the_time('Y') . ' Archives
' . apply_filters('the_title', $sep);
$position++;
// Month Display
echo '- ' . get_the_time('M') . ' Archives
';
$position++;
} else if (is_year()) {
// Year Display
echo '- ' . get_the_time('Y') . ' Archives
';
$position++;
} else if (is_author()) {
// Auhor archive
// Get the author information
global $author;
$userdata = get_userdata($author);
// Display author name
echo '- ' . 'Author: ' . do_shortcode($userdata->display_name) . '
';
$position++;
} else {
$post_type_archive_title = post_type_archive_title('', false);
if (function_exists('is_shop')) {
if (is_shop()) {
$post_type_archive_title = get_the_title(get_option('woocommerce_shop_page_id'));
}
}
echo '
-
' . $post_type_archive_title . '
';
$position++;
}
} else if (is_page()) {
// Standard page
if ($post->post_parent) {
// If child page, get parents
$anc = get_post_ancestors($post->ID);
// Get parents in the right order
$anc = array_reverse($anc);
// Parent page loop
if (!isset($parents)) $parents = null;
foreach ($anc as $ancestor) {
$parents .= '- ' . get_the_title($ancestor) . '
' . $sep;
$position++;
}
// Display parent pages
echo do_shortcode($parents);
// Current page
echo '- ' . get_the_title() . '
';
$position++;
} else {
// Just display current page if not parents
echo '- ' . get_the_title() . '
';
$position++;
}
} else if (is_search()) {
// Search results page
echo '- Search results for: ' . get_search_query() . '
';
$position++;
} else if (is_404()) {
// 404 page
echo '- ' . 'Error 404' . '
';
$position++;
} else if (is_home()) {
echo '- ' . get_the_title(get_option('page_for_posts', true)) . '
';
}
echo '
';
echo '
';
?>
breadcumnb_exist = true;
return ob_get_clean();
};
$___->general_element();