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?
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?
Share Improve this question asked Apr 15, 2015 at 16:31 Olivier PonsOlivier Pons 1171 silver badge7 bronze badges 3- why not just set two attributes in a single shortcode and handle both cases from that one shortcode handler? – Milo Commented Apr 15, 2015 at 17:26
- Honestly, I don't understand the question, but maybe... wordpress.stackexchange/a/100345/21376 – s_ha_dum Commented Apr 15, 2015 at 19:03
- Could you use a php if statement to detect language and display the correct shortcode. – Matt Commented Apr 15, 2015 at 19:09
2 Answers
Reset to default 0Here'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!
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
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744736011a4590749.html
评论列表(0条)