最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Print shortcode according to site language

matteradmin8PV0评论

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 . "']"); ?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far