Breadcrumbs are an essential feature for enhancing website navigation and improving SEO. This guide will cover how to add breadcrumbs without plugins to ensure your WordPress site remains lightweight and efficient while benefiting from better navigation and SEO performance.
📜Table of Contents
What Are Breadcrumbs?🤔💭
Adding breadcrumbs without plugins helps in creating a clean and efficient navigation system. Breadcrumbs improve user experience by allowing visitors to easily trace their steps back to previous pages. They also contribute to better SEO by giving search engines a clearer view of your site’s structure. Using manual breadcrumbs in WordPress ensures that your site runs smoothly without the overhead of additional plugins, keeping your site’s performance at its best.
For example: Home > Blog > SEO Tips > How to Add Breadcrumbs
Why Are Breadcrumbs Important for SEO?🤔💭
- Improved User Experience: Breadcrumbs make it easier for users to navigate your site, reducing frustration and bounce rates.
- Better Indexing: Search engines like Google use breadcrumbs to understand the structure of your site, which can lead to better indexing and rankings.
- Enhanced Click-Through Rates: Breadcrumbs often appear in search results, making your links more attractive to users, which can increase click-through rates.
Types of Breadcrumbs📝
- Location-Based Breadcrumbs: Show the path based on your site’s structure. Example:
Home > Category > Subcategory > Product
. - Attribute-Based Breadcrumbs: Used mostly in eCommerce sites, showing product attributes. Example:
Home > Category > Brand > Product
. - Path-Based Breadcrumbs: Show the user’s path, regardless of the site structure. Example:
Home > Previous Page > Current Page
.
How to Add Breadcrumbs to Your Website🛠️
⚙️Adding Breadcrumbs Using PHP Code
➤1. Create a New Element⚙️
- Click
'Add New
‘ to create a new element. - Log in to Your WordPress Dashboard.
- Go to
'Appearance > Elements
‘.
➤2. Choose the Type of Element⚙️
- Use the ‘Hook‘ element type.
- Add a title.
- Now paste the ‘code‘ which is given below.
<?php
// Function to generate breadcrumbs
function custom_breadcrumbs() {
$separator = '➺';
$home = 'Home'; // Text for the 'Home' link
$before = '<span class="current">'; // Tag before the current crumb
$after = '</span>'; // Tag after the current crumb
if (!is_front_page()) {
echo '<div class="breadcrumbs">';
// Home link
echo '<a href="' . home_url() . '">' . $home . '</a> ' . $separator . ' ';
if (is_category() || is_single()) {
if (is_single()) {
$category = get_the_category();
if ($category) {
echo '<a href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '</a> ' . $separator . ' ';
}
echo $before . get_the_title() . $after;
}
} elseif (is_page()) {
echo $before . get_the_title() . $after;
} elseif (is_tag()) {
echo $before . 'Tag: ' . single_tag_title('', false) . $after;
} elseif (is_author()) {
echo $before . 'Author: ' . get_the_author() . $after;
} elseif (is_archive()) {
echo $before . 'Archive' . $after;
}
echo '</div>';
}
}
// Call the function to display breadcrumbs
custom_breadcrumbs();
?>
<style>
.breadcrumbs {
font-size: 13px;
margin: 0px 0 10px; /* Decrease top margin from 20px to 10px */
padding: 10px;
background: #f7f7f7;
border-radius: 4px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Add a subtle shadow effect */
}
.breadcrumbs a {
color: #0073aa;
text-decoration: none;
}
.breadcrumbs a:hover {
text-decoration: underline;
}
.breadcrumbs .current {
color: #333;
}
</style>
➤3. Configure the Hook:⚙️
- Select Hook Position: Choose where you want your hook to be executed. For example, you can select positions like ‘generate_before_content’ and check mark on ‘Execute PHP‘ opyion.
- Display option: Go to ‘Display Rules Tab’ and select location ‘Post’ > ‘All Posts’.
➤4. Now Save or Publish it.⚙️
🟢This line of code hooks the ‘custom_breadcrumbs
‘ function into the ‘generate_before_content
‘ action in the GeneratePress theme, ensuring that breadcrumbs appear before the main content on every page.
⚡You can add breadcrumbs using plugin : Breadcrumbs widget pro.
🎯Conclusion
Adding breadcrumbs without plugins is an effective way to improve your website’s navigation and SEO without compromising performance. By following the steps outlined above, you can manually add breadcrumbs to your WordPress site, giving you full control over their appearance and functionality. Whether you opt for an HTML/CSS solution, a dynamic PHP approach, or Schema-enhanced breadcrumbs, you’ll be well on your way to creating a more user-friendly and search engine-optimized website.