How to Use Breadcrumbs in WordPress: Simple Guide
breadcrumbs in WordPress, you can add a plugin like Yoast SEO or use theme functions such as yoast_breadcrumb(). Insert the breadcrumb function in your theme files where you want the navigation path to appear.Syntax
Breadcrumbs in WordPress are usually added by calling a function provided by a plugin or theme. For example, Yoast SEO plugin uses yoast_breadcrumb() function.
yoast_breadcrumb( $before, $after ): Outputs breadcrumb navigation.$before: Text or HTML before breadcrumbs (optional).$after: Text or HTML after breadcrumbs (optional).
You place this function inside your theme template files where you want breadcrumbs to show, typically in header.php or single.php.
<?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?>
Example
This example shows how to add breadcrumbs using the Yoast SEO plugin in a WordPress theme. It checks if the function exists and then outputs the breadcrumb trail wrapped in a paragraph with an ID for styling.
<?php // Place this code in your theme file where breadcrumbs should appear if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<nav aria-label="breadcrumb" class="breadcrumb">','</nav>'); } ?>
Common Pitfalls
Not checking if the breadcrumb function exists: This causes errors if the plugin is disabled or not installed.
Placing breadcrumbs in wrong theme files: Breadcrumbs should be in templates that display content, like single.php or page.php, not in unrelated files.
Not styling breadcrumbs: Breadcrumbs need CSS to look good and be accessible.
<?php // Wrong: No function check, may cause error if plugin missing // yoast_breadcrumb('<p>','</p>'); // Right: Check function exists before calling if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p>','</p>'); } ?>
Quick Reference
- Use plugins: Yoast SEO, Breadcrumb NavXT for easy breadcrumb setup.
- Function:
yoast_breadcrumb()outputs breadcrumbs if Yoast SEO is active. - Placement: Insert breadcrumb code in theme files where navigation should appear.
- Accessibility: Wrap breadcrumbs in
<nav>witharia-label="breadcrumb". - Styling: Use CSS to make breadcrumbs clear and responsive.