Skip to content

Commit 0f235f6

Browse files
committed
Add option to use meta titles in breadcrumbs. Closes #704.
Introduces a new 'Use meta titles for breadcrumbs' setting and shortcode attribute, allowing users to choose between meta titles and page titles for breadcrumb output. Updates schema settings UI, translation files, and internal logic to support this feature. Also bumps plugin version to 5.1.4 and updates upgrade routines and notification messaging.
1 parent 3553c1d commit 0f235f6

File tree

11 files changed

+226
-93
lines changed

11 files changed

+226
-93
lines changed

autodescription.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: The SEO Framework
1717
* Plugin URI: https://theseoframework.com/
1818
* Description: An automated, advanced, accessible, unbranded and extremely fast SEO solution for your WordPress website.
19-
* Version: 5.1.3
19+
* Version: 5.1.4
2020
* Author: Sybre Waaijer
2121
* Author URI: https://theseoframework.com/
2222
* License: GPLv3
@@ -53,7 +53,7 @@
5353
*
5454
* @since 2.3.5
5555
*/
56-
define( 'THE_SEO_FRAMEWORK_VERSION', '5.1.3' );
56+
define( 'THE_SEO_FRAMEWORK_VERSION', '5.1.4' );
5757

5858
/**
5959
* The plugin Database version.
@@ -62,7 +62,7 @@
6262
*
6363
* @since 2.7.0
6464
*/
65-
define( 'THE_SEO_FRAMEWORK_DB_VERSION', '5130' );
65+
define( 'THE_SEO_FRAMEWORK_DB_VERSION', '5140' );
6666

6767
/**
6868
* The plugin file, absolute unix path.

bootstrap/upgrade.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function _upgrade( $previous_version ) {
216216
'2701', '2802', '2900',
217217
'3001', '3103', '3300',
218218
'4051', '4103', '4110', '4200', '4270',
219-
'5001', '5050', '5100', '5130',
219+
'5001', '5050', '5100', '5130', '5140',
220220
];
221221
// phpcs:enable WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine
222222

@@ -1002,3 +1002,14 @@ function _do_upgrade_5130() {
10021002
'display_user_edit_options' => 1,
10031003
] );
10041004
}
1005+
1006+
/**
1007+
* Registers new option 'breadcrumb_use_meta_title'. Enabled for upgraded sites, disabled for new sites.
1008+
*
1009+
* @since 5.1.4
1010+
*/
1011+
function _do_upgrade_5140() {
1012+
1013+
if ( \get_option( 'the_seo_framework_initial_db_version' ) < '5140' )
1014+
Data\Plugin::update_option( 'breadcrumb_use_meta_title', 1 );
1015+
}

inc/classes/admin/settings/plugin.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,14 @@ public static function _schema_metabox_general_tab() {
764764
public static function _schema_metabox_presence_tab() {
765765
Template::output_view( 'settings/metaboxes/schema', 'presence' );
766766
}
767+
768+
/**
769+
* Schema Meta Box Breadcrumbs Tab output.
770+
*
771+
* @since 5.1.4
772+
* @see self::schema_metabox() Callback for Schema.org Settings box.
773+
*/
774+
public static function _schema_metabox_breadcrumbs_tab() {
775+
Template::output_view( 'settings/metaboxes/schema', 'breadcrumbs' );
776+
}
767777
}

inc/classes/data/filter/plugin.class.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,18 @@ public static function register_sanitizers_jit() {
150150

151151
$filters = [
152152
'advanced_query_protection' => 'checkbox',
153-
'alter_archive_query' => 'checkbox',
154153
'alter_archive_query_type' => 'alter_query_type',
154+
'alter_archive_query' => 'checkbox',
155155
'alter_search_query_type' => 'alter_query_type',
156156
'alter_search_query' => 'checkbox',
157157
'author_noarchive' => 'checkbox',
158158
'author_nofollow' => 'checkbox',
159159
'author_noindex' => 'checkbox',
160-
'auto_description' => 'checkbox',
161160
'auto_description_html_method' => 'auto_description_method',
161+
'auto_description' => 'checkbox',
162162
'baidu_verification' => 'verification_code',
163163
'bing_verification' => 'verification_code',
164+
'breadcrumb_use_meta_title' => 'checkbox',
164165
'cache_sitemap' => 'checkbox',
165166
'canonical_scheme' => 'canonical_scheme',
166167
'date_noarchive' => 'checkbox',
@@ -171,25 +172,25 @@ public static function register_sanitizers_jit() {
171172
'display_character_counter' => 'checkbox',
172173
'display_list_edit_options' => 'checkbox',
173174
'display_pixel_counter' => 'checkbox',
174-
'display_term_edit_options' => 'checkbox',
175-
'display_user_edit_options' => 'checkbox',
176175
'display_seo_bar_metabox' => 'checkbox',
177176
'display_seo_bar_tables' => 'checkbox',
177+
'display_term_edit_options' => 'checkbox',
178+
'display_user_edit_options' => 'checkbox',
178179
'excerpt_the_feed' => 'checkbox',
179180
'facebook_author' => 'facebook_profile_link',
180181
'facebook_publisher' => 'facebook_profile_link',
181182
'facebook_tags' => 'checkbox',
182183
'google_verification' => 'verification_code',
183184
'home_paged_noindex' => 'checkbox',
184185
'home_title_location' => 'title_location',
186+
'homepage_canonical' => 'fully_qualified_url',
185187
'homepage_description' => 'metadata_text',
186188
'homepage_noarchive' => 'checkbox',
187189
'homepage_nofollow' => 'checkbox',
188190
'homepage_noindex' => 'checkbox',
189-
'homepage_canonical' => 'fully_qualified_url',
190-
'homepage_redirect' => 'fully_qualified_url',
191191
'homepage_og_description' => 'metadata_text',
192192
'homepage_og_title' => 'metadata_text',
193+
'homepage_redirect' => 'fully_qualified_url',
193194
'homepage_social_image_id' => 'absolute_integer',
194195
'homepage_social_image_url' => 'fully_qualified_url',
195196
'homepage_tagline' => 'checkbox',

inc/classes/data/plugin/setup.class.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,11 @@ public static function get_default_options() {
310310
'pint_verification' => '', // Pinterest Verification Code.
311311

312312
// Schema.org.
313-
'ld_json_enabled' => 1, // LD+Json toggle for Schema.
314-
'ld_json_searchbox' => 1, // LD+Json Sitelinks Search Box.
315-
'ld_json_breadcrumbs' => 1, // LD+Json Breadcrumbs.
316-
'knowledge_output' => 1, // Default for outputting the Knowledge SEO.
313+
'ld_json_enabled' => 1, // LD+Json toggle for Schema.
314+
'ld_json_searchbox' => 1, // LD+Json Sitelinks Search Box.
315+
'ld_json_breadcrumbs' => 1, // LD+Json Breadcrumbs.
316+
'breadcrumb_use_meta_title' => 0, // Whether to consider meta titles for breadcrumbs.
317+
'knowledge_output' => 1, // Default for outputting the Knowledge SEO.
317318

318319
// Knowledge general <https://developers.google.com/structured-data/customize/contact-points> - This is extremely extended and valuable. Expect a premium version.
319320
'knowledge_type' => 'organization', // Organization or Person, dropdown.

inc/classes/meta/breadcrumbs.class.php

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,54 +47,99 @@
4747
*/
4848
class Breadcrumbs {
4949

50+
/**
51+
* @since 5.1.4
52+
* @var array The options for breadcrumb generation.
53+
*/
54+
private static $options = [];
55+
5056
/**
5157
* Returns a list of breadcrumbs by URL and name.
5258
*
5359
* @since 5.0.0
60+
* @since 5.1.4 Added the `$options` parameter.
5461
* @todo consider wp_force_plain_post_permalink()
55-
* @todo add extra parameter for $options; create (class?) constants for them.
56-
* -> Is tsf()->breadcrumbs()::CONSTANT possible?
57-
* -> Then, forward the options to a class variable, and build therefrom. Use as argument for memo().
62+
* @todo add extra parameters for $options?
5863
* -> Requested features (for shortcode): Remove home, remove current page.
59-
* -> Requested features (globally): Remove/show archive prefixes, hide PTA/terms, select home name, select SEO vs custom title (popular).
64+
* -> Requested features (globally): Remove/show archive prefixes, hide PTA/terms, select home name.
6065
* -> Add generation args to every crumb; this way we can perform custom lookups for titles after the crumb is generated.
6166
*
62-
* @param array|null $args The query arguments. Accepts 'id', 'tax', 'pta', and 'uid'.
63-
* Leave null to autodetermine query.
67+
* @param array|null $args The query arguments. Accepts 'id', 'tax', 'pta', and 'uid'.
68+
* Leave null to autodetermine query.
69+
* @param array $options Optional. {
70+
* The options for breadcrumb generation
71+
*
72+
* @type ?bool $use_meta_title Whether to consider meta titles before using page titles.
73+
* Default determined by 'breadcrumb_use_meta_title' option.
74+
* }
6475
* @return array[] {
6576
* The breadcrumb list items in order of appearance.
6677
*
6778
* @type string $url The breadcrumb URL.
6879
* @type string $name The breadcrumb page title.
6980
* }
7081
*/
71-
public static function get_breadcrumb_list( $args = null ) {
82+
public static function get_breadcrumb_list( $args = null, $options = [] ) {
83+
84+
// The default options must be ordered alphabetically to ensure consistent cache keys.
85+
self::$options = array_merge(
86+
[
87+
'use_meta_title' => (bool) Data\Plugin::get_option( 'breadcrumb_use_meta_title' ),
88+
],
89+
array_filter(
90+
$options,
91+
fn( $v ) => null !== $v,
92+
),
93+
);
94+
95+
// Sort options alphabetically to ensure consistent cache keys regardless of input order.
96+
ksort( self::$options );
7297

7398
if ( isset( $args ) ) {
7499
normalize_generation_args( $args );
75100
$list = self::get_breadcrumb_list_from_args( $args );
76101
} else {
77-
$list = memo() ?? memo( self::get_breadcrumb_list_from_query() );
102+
$list = memo( null, self::$options ) ?? memo( self::get_breadcrumb_list_from_query(), self::$options );
78103
}
79104

80105
/**
81106
* @since 5.0.0
107+
* @since 5.1.4 Added the `$options` parameter.
82108
* @param array[] {
83109
* The breadcrumb list items in order of appearance.
84110
*
85111
* @type string $url The breadcrumb URL.
86112
* @type string $name The breadcrumb page title.
87113
* }
88-
* @param array|null $args The query arguments. Contains 'id', 'tax', 'pta', and 'uid'.
89-
* Is null when the query is auto-determined.
114+
* @param array|null $args The query arguments. Contains 'id', 'tax', 'pta', and 'uid'.
115+
* Is null when the query is auto-determined.
116+
* @param array $options The options used for breadcrumb generation.
90117
*/
91118
return (array) \apply_filters(
92119
'the_seo_framework_breadcrumb_list',
93120
$list,
94121
$args,
122+
self::$options,
95123
);
96124
}
97125

126+
/**
127+
* Returns the breadcrumb title based on the current setting.
128+
*
129+
* @since 5.1.4
130+
*
131+
* @param array|null $args The query arguments. Accepts 'id', 'tax', 'pta', and 'uid'.
132+
* Leave null to autodetermine query.
133+
* @return string The breadcrumb title.
134+
*/
135+
private static function get_breadcrumb_title( $args = null ) {
136+
137+
if ( self::$options['use_meta_title'] )
138+
return Meta\Title::get_bare_title( $args );
139+
140+
return Meta\Title::get_bare_generated_title( $args );
141+
}
142+
98143
/**
99144
* Gets a list of breadcrumbs, based on expected or current query.
100145
*
@@ -216,7 +261,7 @@ private static function get_singular_breadcrumb_list( $id = null ) {
216261
if ( \get_post_type_object( $post_type )->has_archive ?? false ) {
217262
$crumbs[] = [
218263
'url' => Meta\URI::get_bare_pta_url( $post_type ),
219-
'name' => Meta\Title::get_bare_title( [ 'pta' => $post_type ] ),
264+
'name' => self::get_breadcrumb_title( [ 'pta' => $post_type ] ),
220265
];
221266
}
222267

@@ -237,7 +282,7 @@ private static function get_singular_breadcrumb_list( $id = null ) {
237282
) as $parent ) {
238283
$crumbs[] = [
239284
'url' => Meta\URI::get_bare_term_url( $parent->term_id, $parent->taxonomy ),
240-
'name' => Meta\Title::get_bare_title( [
285+
'name' => self::get_breadcrumb_title( [
241286
'id' => $parent->term_id,
242287
'tax' => $parent->taxonomy,
243288
] ),
@@ -249,19 +294,19 @@ private static function get_singular_breadcrumb_list( $id = null ) {
249294
foreach ( Data\Post::get_post_parents( $post->ID ) as $parent ) {
250295
$crumbs[] = [
251296
'url' => Meta\URI::get_bare_singular_url( $parent->ID ),
252-
'name' => Meta\Title::get_bare_title( [ 'id' => $parent->ID ] ),
297+
'name' => self::get_breadcrumb_title( [ 'id' => $parent->ID ] ),
253298
];
254299
}
255300

256301
if ( isset( $id ) ) {
257302
$crumbs[] = [
258303
'url' => Meta\URI::get_bare_singular_url( $post->ID ),
259-
'name' => Meta\Title::get_bare_title( [ 'id' => $post->ID ] ),
304+
'name' => self::get_breadcrumb_title( [ 'id' => $post->ID ] ),
260305
];
261306
} else {
262307
$crumbs[] = [
263308
'url' => Meta\URI::get_bare_singular_url(),
264-
'name' => Meta\Title::get_bare_title(),
309+
'name' => self::get_breadcrumb_title(),
265310
];
266311
}
267312

@@ -303,7 +348,7 @@ private static function get_term_breadcrumb_list( $term_id = null, $taxonomy = '
303348
) as $parent ) {
304349
$crumbs[] = [
305350
'url' => Meta\URI::get_bare_term_url( $parent->term_id, $parent->taxonomy ),
306-
'name' => Meta\Title::get_bare_title( [
351+
'name' => self::get_breadcrumb_title( [
307352
'id' => $parent->term_id,
308353
'tax' => $parent->taxonomy,
309354
] ),
@@ -313,15 +358,15 @@ private static function get_term_breadcrumb_list( $term_id = null, $taxonomy = '
313358
if ( isset( $term_id ) ) {
314359
$crumbs[] = [
315360
'url' => Meta\URI::get_bare_term_url( $term_id, $taxonomy ),
316-
'name' => Meta\Title::get_bare_title( [
361+
'name' => self::get_breadcrumb_title( [
317362
'id' => $term_id,
318363
'tax' => $taxonomy,
319364
] ),
320365
];
321366
} else {
322367
$crumbs[] = [
323368
'url' => Meta\URI::get_bare_term_url(),
324-
'name' => Meta\Title::get_bare_title(),
369+
'name' => self::get_breadcrumb_title(),
325370
];
326371
}
327372

@@ -352,12 +397,12 @@ private static function get_pta_breadcrumb_list( $post_type = null ) {
352397
if ( isset( $post_type ) ) {
353398
$crumbs[] = [
354399
'url' => Meta\URI::get_pta_url( $post_type ),
355-
'name' => Meta\Title::get_bare_title( [ 'pta' => $post_type ] ),
400+
'name' => self::get_breadcrumb_title( [ 'pta' => $post_type ] ),
356401
];
357402
} else {
358403
$crumbs[] = [
359404
'url' => Meta\URI::get_bare_pta_url(),
360-
'name' => Meta\Title::get_bare_title(),
405+
'name' => self::get_breadcrumb_title(),
361406
];
362407
}
363408

@@ -387,12 +432,12 @@ private static function get_author_breadcrumb_list( $id = null ) {
387432
if ( isset( $id ) ) {
388433
$crumbs[] = [
389434
'url' => Meta\URI::get_author_url( $id ),
390-
'name' => Meta\Title::get_bare_title( [ 'uid' => $id ] ),
435+
'name' => self::get_breadcrumb_title( [ 'uid' => $id ] ),
391436
];
392437
} else {
393438
$crumbs[] = [
394439
'url' => Meta\URI::get_bare_author_url(),
395-
'name' => Meta\Title::get_bare_title(),
440+
'name' => self::get_breadcrumb_title(), // NOTE: has no meta title (yet), but we'll add that in 5.2.0
396441
];
397442
}
398443

@@ -426,7 +471,7 @@ private static function get_date_breadcrumb_list() {
426471
\get_query_var( 'monthnum' ),
427472
\get_query_var( 'day' ),
428473
),
429-
'name' => Meta\Title::get_bare_title(),
474+
'name' => Meta\Title::get_bare_generated_title(), // discrepancy, has no meta title
430475
],
431476
];
432477
}
@@ -448,7 +493,7 @@ private static function get_search_breadcrumb_list() {
448493
self::get_front_breadcrumb(),
449494
[
450495
'url' => Meta\URI::get_search_url(),
451-
'name' => Meta\Title::get_search_query_title(), // discrepancy
496+
'name' => Meta\Title::get_search_query_title(), // discrepancy, has no meta title
452497
],
453498
];
454499
}
@@ -470,7 +515,7 @@ private static function get_404_breadcrumb_list() {
470515
self::get_front_breadcrumb(),
471516
[
472517
'url' => '',
473-
'name' => Meta\Title::get_404_title(), // discrepancy
518+
'name' => Meta\Title::get_404_title(), // discrepancy, has no meta title
474519
],
475520
];
476521
}
@@ -490,7 +535,7 @@ private static function get_404_breadcrumb_list() {
490535
private static function get_front_breadcrumb() {
491536
return [
492537
'url' => Meta\URI::get_bare_front_page_url(),
493-
'name' => Meta\Title::get_front_page_title(), // discrepancy
538+
'name' => Meta\Title::get_front_page_title(), // discrepancy, has no meta title
494539
];
495540
}
496541
}

0 commit comments

Comments
 (0)