ShahiTranslate

Using Shortcodes and Widgets

Overview

ShahiTranslate Pro provides multiple shortcodes and WordPress widgets to place language switchers anywhere on your site. Use shortcodes in posts, pages, or custom templates, and widgets in sidebars or footer areas.

Shortcodes

Language Switcher Shortcode

Basic Usage:
`
[shahitranslate]
`

or shorter version:
`
[stp]
`

What It Does:
Displays the configured language switcher widget inline within your content.

Example:

Add to any post or page:
`
Welcome to our site!

[shahitranslate]

Choose your language above to view content in your preferred language.
`

Result:
Language switcher appears between the text, using your configured widget style.

Shortcode Parameters

Override Widget Style:
`
[shahitranslate widgetlook=”dropdownwith_flags”]
`

Available Styles:

    1. dropdownwithflags – Nice dropdown with flag icons
    2. dropdown – Simple text dropdown
    3. flags – Flags only (inline)
    4. flags_dropdown – Flags with dropdown list
    5. popup – Popup modal
    6. globe – Globe icon
    7. float – Floating button
    8. Example with Style:
      `
      [stp widget_look=”flags”]
      `

      Displays flags inline without dropdown.

      Position Parameter

      Inline vs Floating:
      `
      [shahitranslate position=”inline”]
      `

      Options:

    9. inline (default) – Appears where shortcode is placed
    10. floating – Fixed position (not recommended in shortcode)
    11. Recommended: Always use inline for shortcodes

      Single Language Link Shortcode

      Display Individual Language:
      `
      [stp-lang lang=”es”]
      `

      Displays a single link to Spanish version.

      Parameters:

      | Parameter | Description | Example |
      |———–|————-|———|
      | lang | Language code (required) | lang="es" |
      | label | Custom text label | label="EspaΓ±ol" |
      | widgetlook | Display style | widgetlook="flags_name" |

      Display Styles:

    12. lang_names – “Spanish” (language name)
    13. lang_codes – “ES” (code uppercase)
    14. flags – Flag image only
    15. flags_name – Flag + “Spanish”
    16. flags_code – Flag + “ES”
    17. Examples:

      Text Only:
      `
      [stp-lang lang=”es” widgetlook=”langnames”]
      `
      Output: Spanish

      Flag Only:
      `
      [stp-lang lang=”es” widget_look=”flags”]
      `
      Output: πŸ‡ͺπŸ‡Έ

      Flag + Name:
      `
      [stp-lang lang=”es” widgetlook=”flagsname”]
      `
      Output: πŸ‡ͺπŸ‡Έ Spanish

      Flag + Code:
      `
      [stp-lang lang=”fr” widgetlook=”flagscode”]
      `
      Output: πŸ‡«πŸ‡· FR

      Custom Label:
      `
      [stp-lang lang=”es” label=”En EspaΓ±ol”]
      `
      Output: En EspaΓ±ol

      Multiple Language Links

      Create Custom Language Menu:

      `

      [stp-lang lang=”en” widgetlook=”flagsname”]
      [stp-lang lang=”es” widgetlook=”flagsname”]
      [stp-lang lang=”fr” widgetlook=”flagsname”]
      [stp-lang lang=”de” widgetlook=”flagsname”]

      `

      Output:
      `
      πŸ‡¬πŸ‡§ English
      πŸ‡ͺπŸ‡Έ Spanish
      πŸ‡«πŸ‡· French
      πŸ‡©πŸ‡ͺ German
      `

      Style with CSS:
      `css
      .custom-lang-menu {
      display: flex;
      gap: 15px;
      justify-content: center;
      padding: 20px;
      background: #f5f5f5;
      }

      .custom-lang-menu a {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 15px;
      border: 1px solid #ddd;
      border-radius: 5px;
      text-decoration: none;
      color: #333;
      }

      .custom-lang-menu a:hover {
      background: #fff;
      border-color: #0073aa;
      }

      .custom-lang-menu .stp-current-lang {
      background: #0073aa;
      color: #fff;
      border-color: #0073aa;
      }
      `

      Using Shortcodes in Templates

      PHP Template

      In Theme File (header.php, footer.php, etc.):

      `php

      `

      With Parameters:
      `php
      shortcode( ‘[shahitranslate widgetlook=”flags”]’ ); ?>
      `

      Example in Header:
      `php

      shortcode( ‘[stp widgetlook=”dropdownwithflags”]’ ); ?>

      `

      Page Builder Shortcodes

      Elementor:

    18. Add “Shortcode” widget
    19. Paste: [shahitranslate]
    20. Style the container
    21. Beaver Builder:

    22. Add “Shortcode” module
    23. Enter: [stp widget_look="flags"]
    24. Adjust spacing
    25. WPBakery:

    26. Add “Shortcode” element
    27. Input: [shahitranslate]
    28. Configure column
    29. Divi:

    30. Add “Code” module
    31. Content: [stp]
    32. Style module
    33. Gutenberg Block

      Classic Block:

    34. Add “Shortcode” block
    35. Type: [shahitranslate]
    36. Preview
    37. Paragraph Block:

    38. Add “Paragraph” block
    39. Type: [stp widgetlook="flagsdropdown"]
    40. Converts automatically
    41. HTML Block:
      `html

      [shahitranslate widget_look=”popup”]

      `

      WordPress Widgets

      Language Switcher Widget

      Location: Appearance β†’ Widgets

      Available Widget:

    42. ShahiTranslate Pro – Language Switcher
    43. Adding Widget:

    44. Go to Appearance β†’ Widgets
    45. Find “ShahiTranslate Pro – Language Switcher”
    46. Drag to sidebar (e.g., “Primary Sidebar”)
    47. Configure settings
    48. Click “Save”
    49. Widget Settings:

      | Setting | Description | Options |
      |———|————-|———|
      | Title | Widget title | “Choose Language” |
      | Widget Look | Display style | Dropdown, Flags, etc. |
      | Show Title | Display title | Checkbox |

      Example Configuration:
      `
      Title: Select Language
      Widget Look: Nice Dropdown with Flags
      β˜‘ Show Title
      [Save]
      `

      Widget Areas

      Common Widget Areas:

    50. Primary Sidebar
    51. Footer Widget Area 1
    52. Footer Widget Area 2
    53. Header Widget Area (if theme supports)
    54. Choosing Best Location:

      Sidebar:

    55. Good for blogs
    56. Visible on all pages
    57. Doesn’t interrupt content
    58. Footer:

    59. Universal placement
    60. Doesn’t clutter header
    61. Easy to find
    62. Header:

    63. Most prominent
    64. Quick access
    65. May need custom CSS
    66. Multiple Widget Instances

      Use Different Styles in Different Areas:

      Header Widget (flags only):
      `
      Title: (empty)
      Widget Look: Flags
      ☐ Show Title
      `

      Sidebar Widget (dropdown):
      `
      Title: Languages
      Widget Look: Nice Dropdown with Flags
      β˜‘ Show Title
      `

      Footer Widget (text links):
      `
      Title: Choose Your Language
      Widget Look: Simple Dropdown
      β˜‘ Show Title
      `

      Custom Placement Methods

      Direct Function Call

      In Template Files:

      `php
      exists( ‘stplanguage_switcher’ ) ) {
      stplanguageswitcher( array(
      ‘widgetlook’ => ‘dropdownwith_flags’,
      ‘position’ => ‘inline’
      ) );
      }
      ?>
      `

      Parameters:

    67. widget_look – Style of switcher
    68. position – Display position
    69. Example in Footer:
      `php

      `

      Hook Integration

      Add Switcher to Menu:

      Automatic (via settings):
      `
      Settings β†’ Switcher β†’ Show in Menu
      Select menu location: Primary Menu
      Save
      `

      Manual (via code):
      `php
      function myaddlangtomenu( $items, $args ) {
      if ( $args->theme_location == ‘primary’ ) {
      $switcher = doshortcode( ‘[stp widgetlook=”flags”]’ );
      $items .= ‘

      ‘;
      }
      return $items;
      }
      addfilter( ‘wpnavmenuitems’, ‘myaddlangtomenu’, 10, 2 );
      `

      Add Switcher After Header:
      `php
      function myaddlangafterheader() {
      echo ‘

      ‘;
      echo do_shortcode( ‘[shahitranslate]’ );
      echo ‘

      ‘;
      }
      addaction( ‘wpbodyopen’, ‘myaddlangafter_header’ );
      `

      Elementor Custom Widget

      Create Custom Elementor Widget:

      `php
      // functions.php
      class MyLanguageSwitcherWidget extends \Elementor\WidgetBase {
      public function get_name() {
      return ‘stplanguageswitcher’;
      }

      public function get_title() {
      return ‘Language Switcher’;
      }

      public function get_icon() {
      return ‘eicon-globe’;
      }

      public function get_categories() {
      return [ ‘general’ ];
      }

      protected function render() {
      echo do_shortcode( ‘[shahitranslate]’ );
      }
      }

      function registerstpelementorwidget( $widgetsmanager ) {
      $widgetsmanager->register( new MyLanguageSwitcherWidget() );
      }
      addaction( ‘elementor/widgets/register’, ‘registerstpelementorwidget’ );
      `

      Styling Shortcodes

      CSS Customization

      Target Shortcode Output:

      `css
      / Container /
      .shahitranslate-wrapper {
      margin: 20px 0;
      text-align: center;
      }

      / Dropdown style /
      .shahitranslate-wrapper select {
      padding: 10px 15px;
      border: 2px solid #ddd;
      border-radius: 5px;
      font-size: 16px;
      background: #fff;
      cursor: pointer;
      }

      / Flags inline /
      .shahitranslate-wrapper a {
      margin: 0 5px;
      transition: transform 0.2s;
      }

      .shahitranslate-wrapper a:hover {
      transform: scale(1.1);
      }

      / Current language highlight /
      .stp-current-lang {
      border: 2px solid #0073aa;
      border-radius: 3px;
      padding: 2px;
      }
      `

      Responsive Design

      Mobile-Friendly Shortcodes:

      `css
      / Desktop /
      .shahitranslate-wrapper {
      display: flex;
      justify-content: center;
      gap: 15px;
      }

      / Mobile /
      @media (max-width: 768px) {
      .shahitranslate-wrapper {
      flex-direction: column;
      align-items: center;
      }

      .shahitranslate-wrapper a {
      display: block;
      width: 100%;
      padding: 10px;
      text-align: center;
      border: 1px solid #ddd;
      margin: 5px 0;
      }
      }
      `

      Custom Widget Styling

      Via Settings:
      `
      Settings β†’ Design & Colors

    70. Switcher Text Color: #333
    71. Switcher Background: #fff
    72. Switcher Border: #ccc
    73. Dropdown Text: #000
    74. Dropdown Background: #eee
    75. Custom CSS:
      .shahitranslate-wrapper {
      box-shadow: 0 2px 5px rgba(0,0,0,0.1);
      border-radius: 8px;
      padding: 10px;
      }
      `

      Via Theme CSS:

      `css
      / In your theme’s style.css /
      .widget_shahitranslate {
      background: #f9f9f9;
      padding: 20px;
      border-left: 4px solid #0073aa;
      }

      .widget_shahitranslate .widget-title {
      color: #0073aa;
      font-size: 18px;
      margin-bottom: 15px;
      }
      `

      Use Cases

      1. Blog Post Language Notice

      Scenario: Notify readers they can switch language

      Implementation:
      `html

      This article is available in multiple languages:

      [stp-lang lang=”en” widgetlook=”flagsname”]
      [stp-lang lang=”es” widgetlook=”flagsname”]
      [stp-lang lang=”fr” widgetlook=”flagsname”]

      `

      2. Landing Page Hero Section

      Scenario: Prominent language choice on homepage

      Implementation:
      `html

      Welcome to Our Platform

      Choose your language to get started:

      [shahitranslate widget_look=”popup”]

      `

      3. Footer Global Language Bar

      Scenario: Site-wide language options

      Implementation:
      `php

      `

      4. E-commerce Product Page

      Scenario: Product descriptions in multiple languages

      Implementation:
      `html

      View this product in:
      [stp-lang lang=”en” widgetlook=”langcodes”]
      [stp-lang lang=”de” widgetlook=”langcodes”]
      [stp-lang lang=”fr” widgetlook=”langcodes”]

      `

      5. Navigation Menu Integration

      Scenario: Language switcher in main menu

      Automatic Method:
      `
      Settings β†’ Switcher β†’ Show in Menu
      Menu Location: Primary Menu
      Save Changes
      `

      Manual Method (better control):
      `php
      function addlanguageto_nav( $items, $args ) {
      if ( $args->theme_location == ‘primary’ ) {
      $lang_switcher = ‘

      ‘;
      $items .= $lang_switcher;
      }
      return $items;
      }
      addfilter( ‘wpnavmenuitems’, ‘addlanguageto_nav’, 10, 2 );
      `

      6. Sidebar Contextual Widget

      Scenario: Language widget in blog sidebar

      Widget Configuration:
      `
      Appearance β†’ Widgets
      Sidebar: Primary Sidebar

      Add Widget: ShahiTranslate Pro – Language Switcher
      Title: Read in Your Language
      Widget Look: Nice Dropdown with Flags
      β˜‘ Show Title
      Save
      `

      Advanced Shortcode Usage

      Conditional Display

      Show Shortcode Only on Certain Pages:

      `php
      function conditionallanguageswitcher( $content ) {
      // Only show on single posts
      if ( is_single() ) {
      $switcher = ‘

      ‘;
      $switcher .= doshortcode( ‘[shahitranslate widgetlook=”flags”]’ );
      $switcher .= ‘

      ‘;
      return $content . $switcher;
      }
      return $content;
      }
      addfilter( ‘thecontent’, ‘conditionallanguageswitcher’ );
      `

      Dynamic Parameters

      Change Style Based on Device:

      `php
      function responsivelanguageswitcher() {
      if ( wpismobile() ) {
      return doshortcode( ‘[stp widgetlook=”globe”]’ );
      } else {
      return doshortcode( ‘[stp widgetlook=”dropdownwithflags”]’ );
      }
      }

      // Use in template
      echo responsivelanguageswitcher();
      `

      Custom Shortcode Wrapper

      Create Your Own Shortcode:

      `php
      function mycustomlang_shortcode( $atts ) {
      $atts = shortcode_atts( array(
      ‘style’ => ‘modern’,
      ), $atts );

      $output = ‘

      ‘;
      $output .= ‘🌍 Language:‘;
      $output .= doshortcode( ‘[stp widgetlook=”dropdownwithflags”]’ );
      $output .= ‘

      ‘;

      return $output;
      }
      addshortcode( ‘mylang’, ‘mycustomlang_shortcode’ );

      // Usage:
      // [my_lang style=”modern”]
      `

      Troubleshooting

      Shortcode Not Rendering

      Symptom: [shahitranslate] shows as text

      Causes:

    76. Plugin not activated
    77. Shortcode typed incorrectly
    78. Conflict with page builder
    79. Solutions:
      `

    80. Verify plugin is active:
    81. Plugins β†’ Installed Plugins β†’ ShahiTranslate Pro (Active)

    82. Check spelling:
    83. [shahitranslate] or [stp] (not [shahi-translate])

    84. Use HTML block in Gutenberg instead of Paragraph
    85. Try do_shortcode() in PHP:

    86. `

      Widget Not Appearing

      Symptom: Widget added but not visible on site

      Causes:

    87. Widget area not displayed in theme
    88. No languages enabled
    89. CSS hiding widget
    90. Solutions:
      `

    91. Check widget area:
    92. Visit frontend β†’ View Page Source
      Search for widget area ID

    93. Enable languages:
    94. Settings β†’ Languages β†’ Select at least 2 languages

    95. Check CSS:
    96. Inspect element
      Look for display:none or visibility:hidden

    97. Test different widget area
    98. `

      Styling Issues

      Symptom: Shortcode looks broken or unstyled

      Causes:

    99. CSS not loading
    100. Theme conflict
    101. Missing styles
    102. Solutions:
      `

    103. Clear cache:
    104. Browser cache, plugin cache, server cache

    105. Check CSS loaded:
    106. View Page Source β†’ Look for:
      /wp-content/plugins/shahitranslate-pro/assets/css/frontend.css

    107. Add custom CSS:
    108. Settings β†’ Design β†’ Custom CSS

    109. Increase specificity:
    110. .shahitranslate-wrapper.shahitranslate-wrapper { / styles / }
      `

      Multiple Switchers Conflict

      Symptom: Two switchers on page, both change together

      Expected: They should work independently

      Explanation: This is normal behavior. All language switchers on the same page switch the site language globally. Clicking any switcher affects all content.

      Why: Language preference is site-wide, not per-widget.

      Best Practices

      1. Choose Appropriate Style for Context

      Header/Menu: Globe or compact flags
      Sidebar: Dropdown with flags
      Footer: Simple dropdown or text links
      Content: Popup or flags inline

      2. Don’t Overuse

      Avoid:

    111. Multiple switchers in content
    112. Switcher on every page section
    113. Repetitive placement
    114. Recommended:

    115. One visible switcher per page
    116. Consistent placement across site
    117. 3. Make It Accessible

      Screen Readers:
      `php

      Choose your preferred language
      `

      Keyboard Navigation:
      Ensure dropdown is keyboard accessible (built-in).

      4. Test on Mobile

      Always verify:

    118. Switcher visible on mobile
    119. Touch-friendly (min 44px tap targets)
    120. Doesn’t break layout
    121. 5. Consistent Branding

      Match language switcher design to your theme:
      `
      Settings β†’ Design & Colors
      Use your brand colors
      `

      Next Steps

    122. Language Switcher Options
    123. Design Customization
    124. Translation Methods
    125. Advanced Hooks

Share this article

Was this article helpful?

Help us improve our documentation

Still need help?

Our support team is ready to assist you with personalized guidance for your workspace.

Submit a support ticket