Using a shortcode

From version 2.6 onward, in addition to original method of displaying the widget in a sidebar, it's possible to display it in any page, by simply calling the shortcode, as in the example below:

[aelia_currency_selector_widget title="Widget title (optional)" widget_type="dropdown|buttons"]

The shortcode accepts the following parameters:

  • title
    The widget title (optional)
  • widget_type
    The widget type. The Currency Switcher supports either dropdown or buttons. Further types can be added by implementing a filter in your theme for wc_aelia_cs_currency_selector_widget_types hook. If this parameter is not specified, dropdown widget type will be rendered by default.


How to use the shortcode via PHP

If you would like to call the shortcode from your template's code, you can use WordPress' do_shortcode() function, like in the following example: 

// Display the widget with currencies in a dropdown list
echo do_shortcode('[aelia_currency_selector_widget title="My widget title" widget_type="dropdown"]');

// Display the widget with currencies as buttons
echo do_shortcode('[aelia_currency_selector_widget title="My widget title" widget_type="buttons"]');

For more information about using shortcodes via PHP, please refer to WordPress Codex. Function Reference/do shortcode/.


How to display the currency selector in a menu

If you need to show the selector in a menu, our recommended approach of creating a dedicated sub-menu that will act as the currency selector. This is described in our knowledge base: How to create a currency selector in a navigation menu.


Alternatively, you can use a 3rd party plugin that allows you to enter the shortcode in a menu entry, such as Shortcodes in Menu. When the menu will be rendered on the page, the selector will appear automatically.


Using the WordPress widget

The Currency Selector widget can be dragged and dropped like any standard WordPress widget (see below)/

Simply drag and drop the Currency Selector widget to the appropriate target area.


How to create a new widget area

If you don't have a widget area in the location where you would like to display the Currency Selector, the easiest and most reliable solution is to use the shortcode (see above). If you would rather create a new widget area (called "sidebar", in WordPress), you can do so by following the instructions below:

  1. Open your theme's functions.php file. It's located in /wp-content/themes/<your theme folder>/functions.php.
  2. Register a new widget area with the following code:  

    // Register a new sidebar
    function my_widget_area_init() {
      register_sidebar( array(
        'name' => 'My widget area',
        'id' => 'my_widget_area',
        'before_widget' => '<div class="widget widget_wc_aelia_currencyswitcher_widget">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="rounded">',
        'after_title' => '</h2>',
      ) );
    }
    
    add_action( 'widgets_init', 'my_widget_area_init' );

      

  3. Go to the Wordpress Admin Panel > Appearance > Widgets. The widget area you just added should now be visible on the right. Drag and drop the Currency Selector in the new widget area,
  4. Open the theme file that displays the page section where you would like to display the new widget area (for example, let's suppose /wp-content/themes/<your theme folder>/header.php for the header) and add the following code in the exact place where you would like the area to appear: 

     <?php 
      // Render the new sidebar registered earlier
      dynamic_sidebar('my_widget_area');
    ?>

    Save the file and refresh the page. Now the Currency Selector will be displayed in the area you just added.


You can purchase the Currency Switcher from our online shop.