Below, you’ll find a detailed guide on how to add the Mortgage Calculator / Loan Calculator 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 Mortgage Calculator / Loan Calculator Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Mortgage Calculator / Loan Calculator Plugin and the shortcodes it provides:
"Mortgage Calculator / Loan Calculator is a practical WordPress plugin that allows users to quickly calculate their mortgage or loan payments. Its user-friendly interface ensures seamless navigation."
- []
Mortgage Calculator / Loan Calculator [null] Shortcode
The Mortgage Loan Calculator shortcode is a powerful tool for WordPress sites dealing with real estate and finance. It uses the shortcode [mlcalc] to display a mortgage loan calculator on your site. This calculator is highly customizable, allowing you to set default parameters such as the type of loan (mortgage or loan), calculator size, currency, interest rate, purchase price, loan amount, loan term, and more. It also supports multiple languages, making it a versatile tool for international websites. The shortcode can be used directly in posts, pages, or widgets for easy integration.
Shortcode: [null]
Parameters
Here is a list of all possible null shortcode parameters and attributes:
default
– sets the default calculator type (mortgage, loan, mortgage_only, loan_only)size
– defines the form size (wide, narrow)currency
– sets the currency type (usd, eur, gbp or your own)rate
– determines the interest rateprice
– specifies the purchase pricemterm
– sets the term of the mortgagedown
– defines the down payment percentagetax
– sets the property tax amountinsurance
– specifies the property insurance amountpmi
– sets the private mortgage insurance rateamount
– determines the loan amountlterm
– sets the term of the loanschedule
– defines the amortization schedule (month, year, month_nc, year_nc, none)language
– sets the language of the form (en, de, es, fr, it, pt, ru)
Examples and Usage
Basic example – Display a mortgage calculator with default parameters.
[mlcalc]
Advanced examples
Display a mortgage calculator with a default loan calculator, a narrow size, and the currency set to euros.
[mlcalc default='loan' size='narrow' currency='eur']
Display a mortgage calculator with a default mortgage calculator, a wide size, the currency set to USD, the interest rate set to 3.5%, the purchase price set to $200,000, the mortgage term set to 20 years, the down payment set to 10%, the property tax set to $2,000, the property insurance set to $1,000, the PMI set to 0.5%, the loan amount set to $150,000, the loan term set to 10 years, the amortization schedule set to year with no choice for the visitor, and the language set to Spanish.
[mlcalc default='mortgage' size='wide' currency='usd' rate='3.5' price='200,000' mterm='20' down='10' tax='2,000' insurance='1,000' pmi='0.5' amount='150,000' lterm='10' schedule='year_nc' language='es']
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'mlcalc', 'display_mlcalc' );
Shortcode PHP function:
function display_mlcalc($options = array(), $content = null, $code = "") {
global $mlcalcURL;
if(!empty($code) || (!empty($options) && !empty($options[0]) && ($options[0] == 'mlcalc'))){
$shortcode = true;
// $atts ::= array of attributes
// examples: [mlcalc]
// [mlcalc default='mortgage' size='narrow']
extract( shortcode_atts( array(
// default parameters
'default' => 'mortgage_only', // mortgage|loan|mortgage_only|loan_only
'size' => 'wide', // wide|narrow
'currency' => 'usd', // usd|eur|gbp|ENTER_YOURS
'rate' => '4.5', // interest rate
'price' => '300,000', // purchase price
'mterm' => '30', // mortgage term
'down' => '20', // downpayment in %
'tax' => '3,000', // property tax
'insurance' => '1,500', // property insurance
'pmi' => '0.52',
'amount' => '175,000', // loan amount
'lterm' => '15', // loan term
'schedule' => 'year_nc', // month|year|month_nc|year_nc|none (_nc stands for "no choice" for visitor)
'language' => substr(get_bloginfo('language'), 0, 2), // en|de|es|fr|it|pt|ru
), $options ) );
$default_calculator = $default;
$form_size = ($size == 'narrow' ? 'small' : $size);
$currency_code = $currency;
$interest_rate = $rate;
$purchase_price = $price;
$mortgage_term = $mterm;
$down_payment = $down;
$property_tax = $tax;
$property_insurance = $insurance;
$pmi = $pmi;
$loan_amount = $amount;
$loan_term = $lterm;
$amortization = sanitize_text_field($schedule);
} else {
$shortcode = false;
$options = get_option( 'widget_mlcalc' );
$title = empty( $options['title'] ) ? __('Loan Calculator') : $options['title'];
$default_calculator = empty( $options['default_calculator'] ) ? 'loan' : $options['default_calculator'];
$form_size = empty( $options['form_size'] ) ? 'small' : $options['form_size'];
$currency_code = empty( $options['currency_code'] ) ? 'usd' : $options['currency_code'];
$interest_rate = empty( $options['interest_rate'] ) ? '4.5' : $options['interest_rate'];
$purchase_price = empty( $options['purchase_price'] ) ? '300,000' : $options['purchase_price'];
$mortgage_term = empty( $options['mortgage_term'] ) ? '30' : $options['mortgage_term'];
$down_payment = empty( $options['down_payment'] ) ? '10' : $options['down_payment'];
$property_tax = empty( $options['property_tax'] ) ? '3,000' : $options['property_tax'];
$property_insurance = empty( $options['property_insurance'] ) ? '1,500' : $options['property_insurance'];
$pmi = empty( $options['pmi'] ) ? '0.52' : $options['pmi'];
$loan_amount = empty( $options['loan_amount'] ) ? '175,000' : $options['loan_amount'];
$loan_term = empty( $options['loan_term'] ) ? '15' : $options['loan_term'];
$amortization = empty( $options['amortization'] ) ? 'year_nc' : $options['amortization'];
$language = empty( $options['language'] ) ? substr(get_bloginfo('language'), 0, 2) : $options['language'];
};
if($currency_code == 'eur') $currency_symbol = '€';
if($currency_code == 'gbp') $currency_symbol = '£';
if($currency_code == 'usd') $currency_symbol = '$';
if(empty($currency_symbol)) $currency_symbol = substr(sanitize_text_field($currency_code), 0, 3);
if (!in_array($language, array('en', 'de', 'es', 'fr', 'it', 'pt', 'ru', 'al'))) {
$language = 'en';
}
$display_mortgage_form = $display_loan_form = $display_loan_only = $display_mortgage_only = $display_loan = $display_mortgage = 'style="display:none"';
switch ($default_calculator){
case 'mortgage':
$display_mortgage = $display_mortgage_form = '';
break;
case 'loan_only':
$display_loan_only = $display_loan_form = '';
break;
case 'mortgage_only':
$display_mortgage_only = $display_mortgage_form = '';
break;
case 'loan':
default:
$display_loan = $display_loan_form = '';
break;
}
$hidden = '';
$display_amortization = '';
if (!in_array($amortization, array('month', 'year', 'month_nc', 'year_nc', 'none'))) {
$amortization = 'year_nc';
}
if ((preg_match('/_nc/i', $amortization)) || $amortization == 'none') {
$display_amortization = 'style="display:none"';
$hidden .= '<input type="hidden" name="as" value="' . str_replace('_nc', '', $amortization) . '" />';
}
$as_year = (preg_match('/year/i', $amortization)) ? 'checked="checked"' : '';
$as_month = (preg_match('/month/i', $amortization)) ? 'checked="checked"' : '';
$WL_DIR_PREFIX = $language."/";
// LOAD SCRIPTS
wp_enqueue_script( 'mlcalc-widget-script', plugins_url($WL_DIR_PREFIX.'widget-nj.js', __FILE__), array('jquery') );
// LOAD STYLES
wp_register_style( 'mlcalc-form-small-style', plugins_url('widget-form-small.css', __FILE__) );
wp_register_style( 'mlcalc-form-style', plugins_url('widget-form.css', __FILE__) );
if($form_size == 'small'){
wp_enqueue_style( 'mlcalc-form-small-style' );
} else {
wp_enqueue_style( 'mlcalc-form-style' );
}
if($shortcode) ob_start();
echo "<!-- MLCALC BEGIN -->\r\n";
echo "<script type=\"text/javascript\"><!--\r\n";
echo "mlcalc_currency_symbol = '$currency_symbol';\r\n";
echo "mlcalc_amortization = '$amortization';\r\n";
echo "var _mlcalc_preload_img = new Image(312,44);\r\n";
echo "_mlcalc_preload_img.src='".plugins_url('images/ajax-loader.gif', __FILE__)."';\r\n";
echo "--></script>\r\n";
include($WL_DIR_PREFIX."forms.inc.php");
echo "<!-- MLCALC END -->\r\n";
if($shortcode){
$result = ob_get_contents();
ob_end_clean();
if(is_null($content)){
return $result;
} else {
return $content . $result;
}
}
}
Code file location:
mortgage-loan-calculator/mortgage-loan-calculator/mlcalc.php
Conclusion
Now that you’ve learned how to embed the Mortgage Calculator / Loan Calculator 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.
Leave a Reply