Sunday, October 9, 2022

[FIXED] How to hide a language code from specific page in Polylang plugin

Issue

I am working on WordPress website in which I am using multilingual functionality. and I am using POLYLANG plugin.

I have a situation in which , I have to remove language code from URL , for SPECIFIC PAGES only this is how URL generates : site_url/nl/page_slug

and I want to create URL like this site_url/page_slug

So , for some of the pages I want to remove nl

How do I make it happen ?


Solution

I have used the below filter and the issue was resolved.

function filter_pll_check_canonical_url( $redirect_url, $language ) {
   $redirect_url = str_replace('nl', '', $redirect_url);
}
add_filter( 'pll_check_canonical_url', 'filter_pll_check_canonical_url', 10, 2 );

I am checking with the current URL, if the current URL has a language code so replaced language code with a blank space and URL will seem to like:-

site_url/nl/page_slug => site_url/page_slug


Answered By - Hims V
Answer Checked By - Marilyn (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.