Using a shortcode

From version 2.6 onward, in addition to original method of displaying the widget in a sidebar, it's finally 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

To show the selector in a menu, 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. The easiest and most reliable solution to place the widget in an area of your theme is to add a "widgetised area" in such location. To do so, please follow the instructions below:

  1. Register a new widget area by opening /wp-content/themes//functions.php file and adding the following code:


    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' );
  2. 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,
  3. 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/header.php for the header) and add the following code in the exact place where you would like the area to appear:


     <?php if (dynamic_sidebar('my_widget_area') ) : else : endif; ?>

    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.