Currency Converter Shortcode

Below, you’ll find a detailed guide on how to add the Currency Converter Widget – Exchange Rates Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Currency Converter Widget – Exchange Rates Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Currency Converter Widget – Exchange Rates Plugin and the shortcodes it provides:

Plugin Icon
Currency Converter Widget – Exchange Rates

"Currency Converter Widget – Exchange Rates is a practical plugin for WordPress users. It offers real-time currency conversion and exchange rates, enhancing global eCommerce functions."

★★★★☆ (80) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [currency_bcc]

Currency Converter Widget – Exchange Rates [currency_bcc] Shortcode

The Currency Converter Widget shortcode enables a customizable currency converter on your WordPress site. The shortcode is highly flexible, allowing the user to specify parameters such as the default currencies, language, widget dimensions, color scheme, and various display options. The converter widget is embedded within an iframe for easy integration into any page or post.

Shortcode: [currency_bcc]

Parameters

Here is a list of all possible currency_bcc shortcode parameters and attributes:

  • type – Defines the widget’s type, either ‘fix’ or ‘custom’
  • a – Sets the initial amount to convert
  • f – Sets the initial ‘from’ currency
  • t – Sets the initial ‘to’ currency
  • lang – Sets the language for the widget
  • w – Sets the widget’s width
  • h – Sets the widget’s height
  • c – Sets the widget’s background color
  • fc – Sets the widget’s font color
  • g – Turns on/off gradient background
  • sh – Turns on/off shadow effect
  • b – Turns on/off border
  • fl – Turns on/off flag
  • p – Defines the widget’s display page
  • cs – Sets the widget’s currencies
  • s – Defines the widget’s symbol position
  • mf – Sets the widget’s monetary format
  • df – Sets the widget’s decimal format
  • d – Sets the widget’s date format
  • su – Turns on/off support us

Examples and Usage

Basic example – A basic usage of the currency converter widget shortcode which will display a default currency converter from USD to EUR.

[currency_bcc /]

Advanced examples

Display the currency converter widget with custom width and height, and converting from GBP to USD.

[currency_bcc type="custom" w="300" h="400" f="GBP" t="USD" /]

Display the currency converter widget with a custom background color, font color, and converting from AUD to JPY.

[currency_bcc c="00ff00" fc="000000" f="AUD" t="JPY" /]

Display the currency converter widget with gradient background, shadow, border, and flag turned on, and converting from CAD to INR.

[currency_bcc g="on" sh="on" b="on" fl="on" f="CAD" t="INR" /]

Display the currency converter widget with a custom amount to convert from CHF to NZD.

[currency_bcc a="100" f="CHF" t="NZD" /]

Display the currency converter widget with custom date format, monetary format, and decimal format, converting from SGD to BRL.

[currency_bcc d="2" mf="1" df="2" f="SGD" t="BRL" /]

Display the currency converter widget with support turned on, and converting from ZAR to CNY.

[currency_bcc su="on" f="ZAR" t="CNY" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [currency_bcc] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'currency_bcc', 'currency_bcc_shortcode' );

Shortcode PHP function:

                    function currency_bcc_shortcode( $atts ) {
    $atts = array_change_key_case((array)$atts, CASE_LOWER);

	$atts = shortcode_atts( array(
        'type' => 'fix',
        'a' => '1',
        'f' => 'USD',
        't' => 'EUR',
        'lang' => 'en-US',
		'w' => 200,
		'h' => 350,
		'c' => '4f7ccb',
		'fc' => 'FFFFFF',
        'g' => 'on',
        'sh' => 'on',
        'b' => 'on',
        'fl' => 'on',
        'p' => 'c',
        'cs' => '',
        's' => 'off',
        'mf' => '1',
        'df' => '2',
        'd' => '1',
        'su' => 'on',
	), $atts, 'currency_bcc' );

	$uniq_id = uniqid();
	ob_start();
	?>
	<div id="currency-bcc-<?php echo $uniq_id; ?>" class="currency-bcc">
	</div>

	<script type="text/javascript">
        var wc = document.createElement("DIV");
        function widgetTrigger(type, lang) {
            var uniqID = '<?php echo $uniq_id; ?>';

            var langg = (lang != '-1' && typeof lang != 'undefined') ? '&lang='+lang : "";
            
            var width = (type == 'custom') ? '<?php echo $atts['w']; ?>' : ((type == 'fix') ? 200 : 0);
            var height = (type == 'custom') ? '<?php echo $atts['h']; ?>' : ((type == 'fix') ? 350 : 0);

            var bg_color = '<?php echo $atts['c']; ?>'
            var font_color = '<?php echo $atts['fc']; ?>'

            var amount = '<?php echo $atts['a']; ?>';

            var from = '<?php echo $atts['f']; ?>';
            var to = '<?php echo $atts['t']; ?>'
            
            var gradient = '<?php echo $atts['g']; ?>'
            var shadow = '<?php echo $atts['sh']; ?>'
            var border = '<?php echo $atts['b']; ?>'
            var flag = '<?php echo $atts['fl']; ?>'
            var display = '<?php echo $atts['p']; ?>'
            var currencies = '<?php echo $atts['cs']; ?>'
            var symbol = '<?php echo $atts['s']; ?>'
            var monetary_format = '<?php echo $atts['mf']; ?>'
            var decimal_format = '<?php echo $atts['df']; ?>'
            var date_format = '<?php echo $atts['d']; ?>'
            var support = '<?php echo $atts['su']; ?>'

            wc.id = "wc"+uniqID;
            wc.name = "wc"+uniqID;
            var wc_style = "position:relative;display:inline-block;border:none;min-width:200px;min-height:350px;";
            if (shadow && shadow == 'on') {
                wc_style += "box-shadow:0 0 5px #000;";
            }

            var fr = document.createElement("IFRAME");
            if (width && height) {
                if (width < 200 ) width = 200;
                if (height < 350 ) height = 350;

                fr.width = width+"px";
                fr.height = height+"px";
                wc_style += "width:"+width+"px;";
                wc_style += "height:"+height+"px;";
            }
            else {
                fr.width= "100%";
                if (!height || height < 350 ) height = 350;
                fr.height = height + "px";
                wc_style += "width:100%;";
                wc_style += "height:"+height+"px;";
            }
            wc.style = wc_style;
            wc.innerHTML = ''
            wc.appendChild(fr)

            if(support && support == 'on') {
                var lb=document.createElement("DIV");
                lb.style="position:absolute;display:inline-block;box-sizing:border-box;width:100%;left:0;bottom:0;padding:0 15px;text-align:right;line-height:25px;color:#{{$fc}};font-size:13px;font-family:Arial,Helvetica,sans-serif;"
                var lb_1=document.createElement("A");
                lb_1.innerHTML=from+"/"+to;
                lb_1.href="https://www.currency.wiki/"+from.toLowerCase()+"_"+to.toLowerCase();
                lb_1.rel="nofollow";
                lb_1.target="_blank";
                lb_1.style="float:left;margin:0;padding:0;text-transform:uppercase;line-height:25px;color:#"+font_color+";"
                var lb_2=document.createElement("A");
                lb_2.innerHTML="Currency.Wiki";
                lb_2.href="https://www.currency.wiki";
                lb_2.rel="nofollow";
                lb_2.target="_blank";
                lb_2.style="line-height:25px;margin:0;padding:0;color:#"+font_color+";"
                lb.appendChild(lb_1);
                lb.appendChild(lb_2);
                wc.appendChild(lb);
            }

            fr.id = uniqID;
            fr.name = uniqID;
            fr.style = "border:none;min-width:200px;min-height:350px";
            fr.width = (type == 'custom') ? width+"px" : ((type == 'fix') ? "200px" : "100%");
            fr.height = (type == 'custom') ? height+"px" : ((type == 'fix') ? "350px" : "100%");

            document.getElementById("currency-bcc-"+uniqID).appendChild(wc);
            
            var yp = JSON.stringify({
                cd:uniqID,
                w: width, // width
                h: height, // height
                a: amount ? amount: 1, // amount
                f: from.toUpperCase(), // from currency
                t: to.toUpperCase(), // to currency
                fc: font_color, // font color
                c: bg_color, // bg color
                g: gradient, // gradient bg
                sh: shadow, // shadow
                b: border, // border
                fl: flag, // flag
                p: display, // page - converter or exchange rates
                cs: currencies, // currencies 
                s: symbol, // symbol right, left, off
                mf: monetary_format, // monetary format
                df: decimal_format, // decimal format
                d: date_format, // date
                su: support, // support us
            });
           
            var url = "https://www.currency.wiki/widget/embed?wd=1&f="+from+"&t="+to+"&cs="+currencies+"&d="+date_format+"&tm="+<?php echo time(); ?>+langg;
            url = url.replace(/\"/g, "");
            fr.setAttribute("src", url);
            var w = window.frames[uniqID];
            fr.onload = function() {
                w.postMessage({"t": yp}, "*");
            }            
        }
        widgetTrigger('<?php echo $atts['type']; ?>', '<?php echo $atts['lang']; ?>');
	</script>
	<style>
        .currency-bcc iframe {border:none; outline: none;}
    </style>
	<?php

	$html = ob_get_clean();

	return $html;
}
                    

Code file location:

currency-converter-widget/currency-converter-widget/currency-converter-widget.php

Conclusion

Now that you’ve learned how to embed the Currency Converter Widget – Exchange Rates Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *