Question

I've done a plugin where you can add shortcode like this: [myplugin xx] (where xx is a number which calls a specific content xx).

I have to do a multilingual version of my plugin, so here's my trick: my client writes content xx for language #1 and content yy for language #2.

Then, in an article, he would have to add something like:

[multilingualmyplugin #1 xx][multilingualmyplugin #2 yy]

and then I should just have to write a plugin that is called and change the content before Wordpress calls my first plugin to either [myplugin xx] or [myplugin yy] depending on the domain name. Then Wordpress would call the plugin.

Is it possible and if so, where should I look?

Was it helpful?

Solution

Here's what I've done:created a shortcode where I do [myplugin language="fr" id="5"][myplugin language="us" id="8"] and then, when this page is called, it calls myplugin twice. If it's not on the right page, my plugin returns nothing. So, when this page is called:

  • if it's on a domain like "mydomain.fr" I just call do_shortcode("othershortcode 5")
  • if it's on a domain like "mydomain.us" I just call do_shortcode("othershortcode 8")

It works like a charm!

OTHER TIPS

Shortcode can accept parameters

Here how I did it:

[multilingualmyplugin en_content="22" fr_content="33"]

Then in the shortcode function, you can use if statement:

if($subdomain==='en'){
    //Return content with id $attr['en_content']
}
else if(subdomain==='fr'){
    //Return content with id $attr['fr_content']
}
else{
    //Return something else
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top