Last active
February 27, 2024 19:41
-
-
Save temsool/0f2e14ad5cb4a5aaf3d2b2daae5d76b4 to your computer and use it in GitHub Desktop.
Polylang supported custom breadcrumb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add Shortcode | |
function custom_breadcrumb_shortcode() { | |
// Get the queried object | |
$page = get_queried_object(); | |
// Initialize breadcrumb variable | |
$breadcrumb = '<ul class="breadcrumb">'; | |
// Home link | |
$home_text = ''; // Initialize empty home text | |
$home_text_tr = 'Anasayfa'; // Turkish home text | |
$home_text_en = 'Home'; // English home text | |
$home_text_bg = 'Начало'; // Bulgarian home text | |
// Determine home text based on the current language | |
if (function_exists('pll_current_language')) { | |
$current_lang = pll_current_language(); // Get current language code | |
switch ($current_lang) { | |
case 'tr': | |
$home_text = $home_text_tr; | |
break; | |
case 'en': | |
$home_text = $home_text_en; | |
break; | |
case 'bg': | |
$home_text = $home_text_bg; | |
break; | |
default: | |
$home_text = $home_text_en; // Default to English | |
break; | |
} | |
} else { | |
// Fallback to English if Polylang is not active | |
$home_text = $home_text_en; | |
} | |
$breadcrumb .= '<li><a href="' . esc_url(home_url('/')) . '">' . $home_text . '</a></li>'; | |
// Check if it's a single post | |
if (is_singular('post')) { | |
$breadcrumb .= '<li>' . get_the_title() . '</li>'; | |
} elseif (is_page()) { | |
// Page title | |
$breadcrumb .= '<li>' . $page->post_title . '</li>'; | |
} elseif (is_category()) { | |
// Category archive | |
$breadcrumb .= '<li>' . single_cat_title('', false) . '</li>'; | |
} elseif (is_tag()) { | |
// Tag archive | |
$breadcrumb .= '<li>' . single_tag_title('', false) . '</li>'; | |
} elseif (is_search()) { | |
// Search results page | |
$breadcrumb .= '<li>' . __('Search results for', 'your-text-domain') . ' "' . get_search_query() . '"</li>'; | |
} elseif (is_404()) { | |
// 404 page | |
$breadcrumb .= '<li>' . __('Error 404: Not Found', 'your-text-domain') . '</li>'; | |
} else { | |
// Default for other archive pages | |
$breadcrumb .= '<li>' . post_type_archive_title('', false) . '</li>'; | |
} | |
// End breadcrumb | |
$breadcrumb .= '</ul>'; | |
return $breadcrumb; | |
} | |
add_shortcode('custom_breadcrumb', 'custom_breadcrumb_shortcode'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Style> | |
.breadcrumb { | |
list-style: none; | |
padding: 0; | |
margin: 0; | |
} | |
.breadcrumb li { | |
display: inline-flex; | |
justify-content: center; | |
align-content: center; | |
align-items: center; | |
&,a{ | |
font-family: "Sora"; | |
font-size: 14px; | |
font-weight: 600; | |
} | |
} | |
.breadcrumb li:not(:last-child):after { | |
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='7.586' height='13.268' viewBox='0 0 7.586 13.268'%3E%3Cpath id='Icon_ionic-ios-arrow-down' data-name='Icon ionic-ios-arrow-down' d='M12.824,16.546l5.017-5.021a.944.944,0,0,1,1.339,0,.956.956,0,0,1,0,1.343L13.5,18.556a.946.946,0,0,1-1.308.028L6.464,12.872A.948.948,0,0,1,7.8,11.529Z' transform='translate(-11.246 19.455) rotate(-90)' fill='%23605f5f'/%3E%3C/svg%3E"); | |
margin-left: 5px; | |
display: inline-flex; | |
margin-right: 5px; | |
} | |
/* Adjust the font-size, color, and other properties as needed */ | |
.breadcrumb a { | |
text-decoration: none; | |
color: #605F5F; | |
} | |
.breadcrumb a:hover { | |
text-decoration: none; | |
color: #000; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment