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

Run a filter before outputting the hreflang link #1039

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ function qtranxf_init_language() {
* @return mixed A new URL to be redirected to instead of $url_lang or "false" to cancel redirection.
*/
$target = apply_filters( 'qtranslate_language_detect_redirect', $url_lang, $url_orig, $url_info );

if ( $target !== false && $target != $url_orig ) {
wp_redirect( $target );
// rickfix,, we want redirects to be "permanent" and not default 302
wp_redirect( $target, 301 );
nocache_headers(); // prevent browser from caching redirection
exit();
} else {
Expand Down Expand Up @@ -221,7 +223,7 @@ function qtranxf_detect_language( &$url_info ) {
$url_info['language'] = $lang;

// REST calls should be deterministic (stateless), no special language detection e.g. based on cookie
$url_info['set_cookie'] = ! wp_doing_ajax() && ! qtranxf_is_rest_request_expected();
$url_info['set_cookie'] = ! wp_doing_ajax() && ! wp_doing_cron() && ! qtranxf_is_rest_request_expected();

/**
* Hook for possible other methods
Expand Down
2 changes: 2 additions & 0 deletions qtranslate_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function qtranxf_wp_head() {
// Fallback for unmatched language (default hreflang for SEO)
$hreflangs['x-default'] = qtranxf_convertURL( '', $q_config['default_language'] );

$hreflangs = apply_filters( 'qtranslate_hreflangs', $hreflangs );

foreach ( $hreflangs as $hreflang => $href ) {
echo '<link hreflang="' . $hreflang . '" href="' . $href . '" rel="alternate" />' . PHP_EOL;
}
Expand Down