WPML same slug(url) different language - wordpress

I have this site :
example.com/watches (watches is a custom post type)
There are two available languages : EN(default language), GR.
When i change to GR (while on page example.com/watches)
it redirects to example.com/el/watches which is right.
When i am on example.com/watches/rolex and i try to change language it redirects to example.com/el/taxwatches/rolex-el but i want it just to be example.com/el/watches/rolex/.
taxwatches is my custom taxonomy.
rolex-el is the slug of the term inside that taxonomy.
Has anyone experienced an issue like this before?
I've tried to save the permalinks again and check my WMPL settings but i can't see something wrong.
EDIT 1 : If i manually go to example.com/el/watches/rolex it will work fine.
Both example.com/el/watches/rolex and example.com/el/taxwatches/rolex-el work.
EDIT 2: From what i understand WPML takes the slugs, is there a way to change it so it takes the names?

Ok so for anyone having problems with multi language sites - but want to have the "same slugs" in the urls (will never be same slugs - but going to look like that) read the below.
WPML uses slugs which are created from the wordpress core structure - you can't have two slugs with the exactly same name. If default language is EN and you have a secondary, in my case GR, then one slug is going to be "myslug" and the other "myslug-gr" (you can customize this "-gr" through WPML settings).
In functions.php you can filter the "wpml_ls_filter" function which is fired when your Language switcher is created.
Code as below :
add_filter('icl_ls_languages', 'wpml_ls_filter');
function wpml_ls_filter($languages) {
foreach ($languages as $lang_code => $language) {
$mTempString = $languages[$lang_code]['url'];
echo $mTempString; // HERE
// If "tax" is found in that string, replace it with "" - remove it.
if (strpos($mTempString, "tax") !== false) {
$languages[$lang_code]['url'] = str_replace("tax", "", $mTempString);
}
}
return $languages;
}
The above echo is going to show you the url that is created (and you can manipulate it) of each language button when pressed whenever you visit a page/post.
I haven't wrote a complete solution because that really depends on what you want to do. For example the above code helped me achieve to remove "tax" if found in the url.

This answer is providing an alternative way to achieve multiple languages with same slug
Polylang with Polylang Slug these 2 plugins can do
https://wordpress.org/plugins/polylang/
https://github.com/grappler/polylang-slug/

You can use my plugin, it is based on the newest Polylang Pro module and does what you need: https://github.com/lufton/polylang-share-slug

Related

WordPress custom URL guessing before the default guessing

I believe a solution to this would apply to any WordPress core function, but this is a specific example I'm having struggle with.
I want to make some custom URL guessing, before the default one. It would look something like this:
function custom_redirect_guessing( $requested_url = null, $do_redirect = true ) {
// My custom logic
// If none of my logic checks out, execute the default one.
default_guessing();
}
add_filter( 'redirect_canonical', 'custom_redirect_guessing' );
But this of course doesn't work.
My main goal is to fix URLs coming from the previous website, for example:
example.com/fr/news/slug => example.com/fr/slug
This would normally work, but my client's previous website has all the slugs in EN, so WP's automatic guessing redirects all trafic to EN, instead of keeping the visitor in the respect language.
Currently, WP's automatic guessing is doing something like this (because FR and EN share the same slug):
example.com/fr/news/slug => example.com/en/slug
Any ideas on how to do fix this?

Wordpress: Polylang and ACF Options page on ajax calls takes default language value

I'm working on a website, which is multilingual.
We're using Polylang and the ACF custom fields plugin.
Works fine in general, the issue is with the ACF Option pages.
The option pages are translated also in different languages.
The content we are taking from there is being displayed according to translation - in english on the english version of a page, french on the french etc.
The problem: We have a contact us form, where we take the recipients email address from the ACF option pages.
(We want to send it to a different recepient when its a different language.)
Here it always takes the email address from the default language option page and I don't understand why.
We are taking the email recipient for the ajax call with get field command, like on pages displaying content:
get_field('service_email', 'option' );
Anyone got an idea what could cause this? Or where to look?
In the end we found the solution. It took a bit of digging, but I hope this helps if anyone encounters the same issue.
We needed to add the following setup in the functions.php of our theme to have the ACF options pages also translated for the each language:
// Translating Options Page Compatibility
// add filter with the path to your acf installation
add_filter('acf/settings/default_language', 'my_settings_default_language');
add_filter('acf/settings/current_language', 'my_settings_current_language');
function my_settings_default_language( $lang ) {
if($lang == "") {
$lang = pll_default_language(); // pll_ is a polylang function
}
return $lang;
}
function jfrog_settings_current_language( $lang ) {
$lang = pll_current_language();
return $lang;
}
Side Note: We're using a theme installed version of ACF.
hope this helps, Cheers

Can I edit my .htaccess to write some WorldPress URL's (custom rewrites)?

So here's the problem: We don't like the fact that WordPress doesn't allow duplicate slugs, even for sub categories meaning we cannot have urls like:
product-1/guides
product-1/articles
product-2/guides
product-2/articles
That's very annoying! One solution we are considering is setting up our slugs like this:
product-1/product-1-guides
product-1/product-1-articles
product-2/product-2-guides
product-2/product-2-articles
But in our htaccess - can we use it to pick up such urls and rewrite them as prettier urls which have the product name removed from the sub folder? We don't mind hard coding these as we'll only ever have 5-10 products on the site.
This would keep the WordPress install happy with unique slugs, but the SEO tick in the box with better looking urls.
I just need a hand with the syntax please?
EDIT 1:
After looking at the WordPress Rewrite API, I'm failing to get anywhere with what I think is a really simple test. I have the following code in my functions.php which is running as I tested an echo, but no rewriting is taking place?
add_action( 'init', 'productRewrites' );
function productRewrites() {
add_rewrite_rule('^wordpress/james?','index.php?author_name=jwilson','top');
}
Nothing happens when I hit:
mysite.com/wordpress/james
Edit 2:
Cool I realise I now have to click save each time. The problem I now have is the following does not work not when I use $matches[1] - it only works if I hard code the author_name value (to jwilson for example):
function productRewrites() {
add_rewrite_rule(
"writer/([^/]+)/?",
"index.php?author_name=$matches[1]",
"top");
}
When I use $matches[1] it just returns everything! So clearly isn't using ([^/]+) in the url?!
you have to reset permalink structure
in order to do that, move to Settings -> Permalinks and press Save changes button

add custom field template to theme admin page

in WP admin how to add the custom field template plugin to a theme page?
it automatically shows in posts and pages but i want this in the theme page. the theme am using is from iwak "creations" portfolio page.
what files do i need to modify to add this?
It's very hard to say what you need to modify without being able to look at the code. Being a premium theme, we can't just download it and take a look.
Having said that, the theme may use the WordPress custom post type functionality. Search the code for a call to the register_post_type function. If it's used, you may be in luck. Either
add 'custom-fields' to the supports argument in that call, or
call add_post_type_support after the post type is registered. The $post_type parameter will be the first value passed to the register_post_type function, and the $supports parameter will be 'custom-fields'.
Daniel, are you using this Custom Post Type Plugin - http://wordpress.org/extend/plugins/custom-field-template/screenshots/? I've used it before, and the guy who created it is Japanese, so his personal page isn't very useful as far as support for english goes.
I had some trouble with this at first. But what I think you're trying to do is add the custom fields to your new pages you've created, correct?
It's not very straightforward, but once it works it's pretty awesome.
Basically, when you set up the plugin you create these different "Custom fields," right? Well part of that should look like this:
[Custom Field Name]
type = textarea
rows = 4
cols = 40
tinyMCE = true
htmlEditor = true
Ok, so once you've created those "Custom fields" keep note of the part in brackets. You'll add this to your template pages:
<?php getCustomField('Custom Field Name'); ?>
Now when you enter the info in the pages or posts, the content should appear as you've entered it.

Change management in WordPress

I have a beginner question. What is the best way to address the change management issues in WordPress? I have an all-pages WordPress installation. Suppose name of some event or an entity changes from A to B, then I have to go to all the pages to make that change. Is there any better way of doing it? Like externalization or something.
Or the way similar to how WordPress handle blog name using bloginfo() function. You change blog name at one place and it is reflected everywhere.
Thanks,
Paras
If a URL on your site changes, it is always wise to leave a redirect to the new page. This will help your visitors and search engines. If you create redirects, it doesn't matter too much if you still have a link to the old address in one of your posts. There will probably be a plugin for this, but I don't know which one.
If you really want to keep all links pointing to the latest version, you could replace them with shortcodes that are evaluated to the real URL. <a href="[linkto postid=123]"> would then result in <a href="/2010/08/05/some-post">. I think this is doable, but I don't know whether a plugin already exists for this.
You can also use this technique to replace short snippets, like your company name. The Shortcode API is really easy:
// [company_name]
function replace_company_name($atts) {
return "My Awesome Company";
}
add_shortcode('company_name', 'replace_company_name');
// More generic
// [replace r='company_name']
// [replace r='company_motto']
function do_replacement($atts) {
$replacements = array(
'company_name' => 'My Awesome Company',
'company_motto' => 'A Company so Awesome even you would want to work here!',
);
return $replacements[$atts['r']];
}
add_shortcode('replace', 'do_replacement');
You can hardcode the strings in your plugin code, or you could create a Wordpress options page where users can add and edit new shortcodes.

Resources