Skip to content

Commit

Permalink
Fix Breadcrumbs Trails (#4)
Browse files Browse the repository at this point in the history
* feat: install wp-breadcrumbs package

* bump plugin version

* refactor: breadcrumbs generator

* add changelog

* fix: remove extra line break

* Generated

* fix: update breadcrumbs package
  • Loading branch information
mahdiyazdani authored Aug 22, 2024
1 parent dc86552 commit 70e4650
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 75 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"archive": {
"exclude": [
"!/languages",
"vendor",
"!vendor/*",
"node_modules",
"CODE_OF_CONDUCT.md",
"composer.json",
Expand Down Expand Up @@ -41,7 +41,8 @@
"license": "GPL-3.0",
"name": "mypreview/seo-ready",
"require": {
"php": ">=7.4"
"php": ">=7.4",
"mahdiyazdani/wp-breadcrumbs": "^1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "0.7.2",
Expand Down
66 changes: 63 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions languages/seo-ready.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GPL-3.0.
msgid ""
msgstr ""
"Project-Id-Version: SEO Ready 2.3.0\n"
"Project-Id-Version: SEO Ready 2.3.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/seo-ready\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-08-19T12:45:57+00:00\n"
"POT-Creation-Date: 2024-08-22T18:16:34+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.8.1\n"
"X-Domain: seo-ready\n"
Expand All @@ -34,34 +34,34 @@ msgid "MyPreview"
msgstr ""

#. translators: 1: Open anchor tag, 2: Close anchor tag.
#: seo-ready.php:79
#: seo-ready.php:86
msgctxt "plugin link"
msgid "%1$sCommunity support%2$s"
msgstr ""

#. translators: 1: Open anchor tag, 2: Close anchor tag.
#: seo-ready.php:81
#: seo-ready.php:88
msgctxt "plugin link"
msgid "%1$sDonate%2$s"
msgstr ""

#. translators: 1: Open anchor tag, 2: Close anchor tag.
#: seo-ready.php:81
#: seo-ready.php:88
msgid "Donate to support this plugin"
msgstr ""

#: seo-ready.php:222
#: seo-ready.php:229
msgid "Est. reading time"
msgstr ""

#. translators: %s: Estimated reading time in minutes.
#: seo-ready.php:224
#: seo-ready.php:231
msgid "%s minute"
msgid_plural "%s minutes"
msgstr[0] ""
msgstr[1] ""

#: seo-ready.php:226
#: seo-ready.php:233
msgid "Written by"
msgstr ""

Expand Down
8 changes: 5 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: https://www.buymeacoffee.com/mahdiyazdani
Requires at least: 5.5
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 2.3.0
Stable tag: 2.3.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -27,7 +27,7 @@ Enhance your website's search engine visibility while optimizing content for bot
Optimize the way search engines understand and display your content. Selecting relevant schema types will improve how pages and posts are interpreted and make them more likely to display in rich snippets, potentially increasing visibility in search results. The article type dropdown menu will also allow you to customize the schema settings based on the content, thus properly presenting the content in the search engine listings.

## Social Media Integration
Control over how the content appears on platforms like Facebook and Twitter/X, including what images, titles, and descriptions to use ensures posts look their best when shared, captures attention and generates engagement.
Control over how the content appears on platforms like Facebook and Twitter/X, including what images, titles, and descriptions to use ensures posts look their best when shared, captures attention and generates engagement.

## Breadcrumbs Block
The schema-enhanced Breadcrumbs block helps boost both user navigation and SEO. Breadcrumbs not only help users understand their location on a site but also provide search engines with valuable context.
Expand All @@ -36,7 +36,6 @@ The Breadcrumbs block settings will allow you to personalize the delimiter, hide
## Why Choose SEO Ready?
SEO Ready delivers all the essential tools needed to optimize your WordPress website for search engines and social media, helping you reach a wider audience and significantly improving your site’s visibility. Its user-friendly interface and comprehensive feature set make SEO Ready the perfect choice for anyone looking to enhance their SEO efforts with minimal hassle.


== Installation ==
= Minimum Requirements =

Expand Down Expand Up @@ -92,6 +91,9 @@ Yes, our dedicated support team is ready to assist you with any questions or iss
3. Customize how your content appears on Facebook and Twitter/X with the SEO Ready plugin's social media settings.

== Changelog ===
= 2.3.1 =
* Fix blog breadcrumb trails not displaying in the single post view.

= 2.3.0 =
* Add "Breadcrumbs" editor block.

Expand Down
70 changes: 11 additions & 59 deletions seo-ready.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Plugin Name: SEO Ready
* Plugin URI: https://mypreview.one
* Description: A lightweight SEO plugin to generate most commonly used meta tags. Designed for privacy, speed, and accessibility.
* Version: 2.3.0
* Version: 2.3.1
* Author: MyPreview
* Author URI: https://mypreview.one
* Requires at least: 5.9
Expand All @@ -37,6 +37,8 @@
* Domain Path: /languages
*/

use SEO_Ready\Breadcrumbs;

if ( ! defined( 'ABSPATH' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
Expand All @@ -45,6 +47,11 @@

define( 'SEO_READY_VERSION', '2.3.0' );

/**
* Loads the PSR-4 autoloader implementation.
*/
require_once untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/vendor/autoload.php';

/**
* Load the plugin text domain for translation.
*
Expand Down Expand Up @@ -723,74 +730,19 @@ function seo_ready_estimated_reading_time_minutes( $post_id ) {
*/
function seo_ready_generate_breadcrumbs_trails( $post_id = null, $attributes = array() ) {

$post_id = seo_ready_get_localized_post_id();

// Leave early if no post id is found.
if ( ! seo_ready_is_post_exists( $post_id ) ) {
return array();
}

$post_type = get_post_type( $post_id );

if ( false === $post_type ) {
return array();
}

$ancestor_ids = array();
$has_post_hierarchy = is_post_type_hierarchical( $post_type );

if ( $has_post_hierarchy ) {
if ( ! empty( $ancestor_ids ) ) {
$ancestor_ids = get_post_ancestors( $post_id );
}
} else {
$terms = get_the_terms( $post_id, 'category' );

if ( $terms && ! is_wp_error( $terms ) ) {
$term = get_term( $terms[0], 'category' );
$ancestor_ids[] = $term->term_id;
$ancestor_ids = array_merge( $ancestor_ids, get_ancestors( $term->term_id, 'category' ) );
}
}

$trails = array();
$breadcrumbs = new Breadcrumbs\Trails();

// Prepend site title breadcrumb if available and set to show.
$site_title = get_bloginfo( 'name' );
$site_title_override = $attributes['siteTitleOverride'] ?? '';

if ( $site_title && empty( $attributes['hideSiteTitle'] ) ) {
$site_title = ! empty( $site_title_override ) ? $site_title_override : $site_title;
$trails[] = array(
$site_title,
get_bloginfo( 'url' ),
);
}

if ( $has_post_hierarchy ) {
// Construct remaining breadcrumbs from ancestor ids.
foreach ( array_reverse( $ancestor_ids ) as $ancestor_id ) {
$trails[] = array(
get_the_title( $ancestor_id ),
get_the_permalink( $ancestor_id ),
);
}
} else {
foreach ( array_reverse( $ancestor_ids ) as $ancestor_id ) {
$trails[] = array(
get_cat_name( $ancestor_id ),
get_category_link( $ancestor_id ),
);
}
$breadcrumbs->add_crumb( $site_title, get_bloginfo( 'url' ) );
}

// Append current page title if set to show.
if ( empty( $attributes['hideCurrentPageTrail'] ) ) {
$trails[] = array(
get_the_title( $post_id ),
get_the_permalink( $post_id ),
);
}
$trails = $breadcrumbs->generate();

seo_ready_generate_breadcrumb_list_item( $trails );

Expand Down

0 comments on commit 70e4650

Please sign in to comment.