Add Yoast SEO Breadcrumb to WordPress Theme

  1. خانه
  2. /
  3. PHP
  4. /
  5. Add Yoast SEO Breadcrumb to WordPress Theme

Breadcrumbs are a way to help your users better navigate your site and its structure. Additionally, they can appear on Google and provide a better user experience.

To make it easy for users and search engines to navigate your site, you need more than breadcrumbs. Yoast SEO Premium comes with an internal linking feature, as well as content filters. With those tools, you can keep your content structured, findable, and up-to-date.

The Yoast SEO breadcrumbs will output JSON-LD data in the source code. We have found this to be the most reliable method of implementing breadcrumbs for rich snippets.

So, how can we add this breadcrumb in our theme? The steps below are a temporary solution as manual edits made to theme files may be overwritten with future theme updates.

Copy the following code into your theme where you want the breadcrumbs to be.

if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}

NOTE: Depending on your theme you may or may not need to add in the beginning <php and ending ?> php tags.

Common places where you could place your breadcrumbs are inside your single.php and/or page.php file just above the page’s title. Moreover, another option that makes it really easy in some themes is by just pasting the code in header.php at the very end.

If you are using WordPress Twenty Twenty theme, and you want to have a breadcrumb like I used in this site, below the title of post, copy above code in themes/twentytwenty/template-parts/entry-header.php line ~46 and find the_title function, add the code after it. e.g. :

#/themes/twentytwenty/template-parts/entry-header.php

if ( is_singular() ) {
	the_title( '<h1 class="entry-title">', '</h1>' );
	if ( function_exists('yoast_breadcrumb') ) {
		yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
	}
} else {
	the_title( '<h2 class="entry-title heading-size-1"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2>' );
}

Hope you find it useful, if you cannot find the right place in your current theme and the developer cannot help you, feel free to ask for support at comment section.

کامنت ها (0)

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

این قسمت نباید خالی باشد
این قسمت نباید خالی باشد
لطفاً یک نشانی ایمیل معتبر بنویسید.
شما برای ادامه باید با شرایط موافقت کنید

برای امنیت، از سرویس reCAPTCHA Google حریم خصوصی و شرایط استفاده استفاده کنید.

دسته بندی:
PHPآموزشیتکه کدتوسعهوردپرس
تگ ها:
mPDF and PHP Requirement Check
اتصال به 1.1.1.1 در ویندوز (آپدیت دی 1400)
فهرست