Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumb filter hooks passing original values #270

Open
RavanH opened this issue Mar 26, 2024 · 0 comments
Open

Breadcrumb filter hooks passing original values #270

RavanH opened this issue Mar 26, 2024 · 0 comments

Comments

@RavanH
Copy link

RavanH commented Mar 26, 2024

Is your feature request related to a problem? Please describe.

The breadcrumb filters rank_math/frontend/breadcrumb/settings and rank_math/frontend/breadcrumb/strings initially pas an empty array, instead of the default settings and strings. This makes them less useful than they could be.

For example, to get translation strings from a plugin like Polylang, we need the original string. If the rank_math/frontend/breadcrumb/strings would pass the original strings (instead of an empty array) then the original string could be used like pll__( $string ); to get the translation dynamically. Without it, the filter must jump to many more hoops to first fetch the original string, then return the translation.

Describe the solution you'd like

If the original values are passed to the filter, then any added filters can use them if needed.

Describe alternatives you've considered

A filter can hardcode translation strings, but if the original value is changed in the Rank Math settings, the filter code must be adapted accordingly.

A filter can do the work to fetch the original values, but will depend on Rank Math specific functions. This makes them less future proof. For instance, the filter might use RankMath\Helper::get_settings( 'general.breadcrumbs_prefix' ) to get the original prefix setting, but if the Helper class is changed at any point in the future, the code will break.

Additional context

An example of a filter that I expected to work but fails, due to an empty array:

add_filter( 'rank_math/frontend/breadcrumb/strings', function( $strings ) { 
	$strings['prefix']    = pll__( $strings['prefix'] ); 
	$strings['home']      = pll__( $strings['home'] ); 
	$strings['home_link'] = pll_home_url( pll_current_language() );
	$strings['error404']  = pll__( $strings['error404']  );

	return $strings;
} );

Instead, the following is needed:

add_filter( 'rank_math/frontend/breadcrumb/strings', function( $strings ) { 
	$strings['prefix']    = pll__( RankMath\Helper::get_settings( 'general.breadcrumbs_prefix' ) ); 
	$strings['home']      = pll__( RankMath\Helper::get_settings( 'general.breadcrumbs_home_label' ) ); 
	$strings['home_link'] = pll_home_url( pll_current_language() );
	$strings['error404']  = pll__( RankMath\Helper::get_settings( 'general.breadcrumbs_404_label' ) );

	return $strings;
} );

Please let filters be filters :)

RavanH added a commit to RavanH/seo-by-rank-math that referenced this issue Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant