hoe Aelia Currency Switcher includes a currency selector widget, which can be displayed anywhere by using a shortcode or the built-in widget component. Please find below the instructions to use each feature.
1. Displaying the widget using the shortcode
By using the currency selector shortcode, It's possible to display the widget on any page. You can use the shortcode as in the example below:
[aelia_currency_selector_widget title="Widget title (optional)" widget_type="dropdown|dropdown_flags|buttons" currency_display_mode="show_currency_code|show_currency_name"]
The shortcode accepts the following parameters:
- title
The widget title (optional). - widget_type
The widget type. The Currency Switcher supports the following widget types:- dropdown (default). A simple dropdown selector. By default, this widget will display the currency name (see argument "currency_display_mode" below.
- dropdown_flags. A dropdown selector, with flags displayed next to each currency. By default, this widget will display the currency codes. Note: this widget type is available since version 4.12.0 of the Aelia Currency Switcher.
- buttons. A selector showing buttons that visitors can click to select the currency. By default, this widget will display the currency codes.
- currency_display_mode
This argument specifies what label will be displayed for each currency. It can have the following values:- show_currency_name (default). Displays the currency name (e.g. Euro, Pound Sterling, Unites States Dollar).
- show_currency_code. Displays the currency code (e.g. EUR, GBP, USD).
Additional custom 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 in a dropdown list, with flags echo do_shortcode('[aelia_currency_selector_widget title="My widget title" widget_type="dropdown_flags"]'); // 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/.
2. How to use the currency selector shortcode 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.
3. How to display the currency selector using a 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. The configuration form will allow you to choose the widget type and additional options.
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:
- Open your theme's functions.php file. It's located in /wp-content/themes/<your theme folder>/functions.php.
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' );
- 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,
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:
// 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.