最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Print shortcode according to site language

programmeradmin2浏览0评论

I'm creating my website with "elementor plugin". So I used to customize the default WordPress search result page since I couldn't access it with elementor.

Anyway, I tried to display my custom elementor footer using a short code:

<?php echo do_shortcode("[INSERT_ELEMENTOR id='319']"); ?>

The code above displays my footer in Arabic version.

<?php echo do_shortcode("[INSERT_ELEMENTOR id='3183"]'); ?>

And this one above is for English version.

How can I switch to any custom footer I want according to site language?

I'm creating my website with "elementor plugin". So I used to customize the default WordPress search result page since I couldn't access it with elementor.

Anyway, I tried to display my custom elementor footer using a short code:

<?php echo do_shortcode("[INSERT_ELEMENTOR id='319']"); ?>

The code above displays my footer in Arabic version.

<?php echo do_shortcode("[INSERT_ELEMENTOR id='3183"]'); ?>

And this one above is for English version.

How can I switch to any custom footer I want according to site language?

Share Improve this question edited Apr 12, 2019 at 11:42 norman.lol 3,2413 gold badges30 silver badges35 bronze badges asked Apr 12, 2019 at 9:39 AtefAtef 1232 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

That's probably basic PHP. As all that's needed would be some kind of map/array and then switch use the id according to what get_locale() returns.

<?php

// Provide a map if locales and shortcode IDs.
$custom_footer = [
  'ar'    => '319',
  'en_US' => '3181',
  // ... and so on
];

// Get the current language.
$current_language = get_locale();

// Get the right shortcode ID.
$shortcode_id = $custom_footer[$current_language];

?>

<?php echo "Just for debugging, the current language is: " . $current_language; ?>

<?php echo do_shortcode("[INSERT_ELEMENTOR id='" . $shortcode_id . "']"); ?>
发布评论

评论列表(0)

  1. 暂无评论