PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

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

 October 09, 2022     polylang, url-rewriting, wordpress     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing