Calculate Values with Shortcodes
Calculate Values with Shortcodes
Description
Have you ever wanted to calculate some values dynamically to display in your posts? Let’s say you have some shortcodes that retrieve values in real time from the database. Now you want to perform some calculations on those shortcodes and display the results in your posts or pages. This plugin allows you to use a simple [calculate] shortcode with the expression inside to display these values in real time!
So an expression like [calculate]2+3*4[/calculate] will return the value “14”. Now just replace any numeric value with a shortcode that returns a number and you’re set.
Attributes
You can use the “dec” attribute to specify the number of decimal digits you want to round the result up to. The default is “0”. Meaning that by default, all results will be rounded to an integer.
For international number formatting, you can use the “int” attribute to specify a locale. For example, int=”fr_FR” will format the numbers according to the french locale!
See screenshots for illustrations.
For example, you can use this to display values in a table that are constantly changing. Or refer to dynamic prices multiplied by some value. The possibilities are endless.
You can see a real world example of this plugin at work here:
The best part is, it doesn’t use dangerous functions like “eval” to work – which means all authors can use it safely. There’s no danger of it breaking your site.
Installation
- You can install the plugin from WordPress’s plugin repository.
- Just click “Activate” to enable the shortcode.
- Or download the zipped file
- Then go to Plugins -> Add New
- Click “Upload Plugin” at the top of the screen
- Use “Choose File” , select the zip file you just downloaded, and click “Install Now”
- On the next screen, click “Activate”
Screenshots
Faq
- What math expressions can I use with this plugin?
This plugin supports all expressions allowed by EvalMath. You can see the documentation on this git page: https://github.com/dbojdo/eval-math
Reviews
Great little tool for inline calculations
By cheekycreative on January 21, 2022
Thank You!
By phomar on December 2, 2020
Fantastic plugin!!
By ukbestrong on August 26, 2020
The plugin is not compatible with Storefront + WooCommerce.
By pescianschi on November 5, 2019
Great Plugin and Best Support
By Forson on May 16, 2019
Very easy to use
By searchngp on November 7, 2018
Best Plugin And Best Support Ever
By mohali1988 on September 24, 2018
Works and opens a lot of possibilities
By jaredj on July 17, 2018
Great plugin
By Highedge (benandtimmies) on June 4, 2018
Changelog
2.3
Changed <? to <?php in evalmath.class.php
Removed the deprecated “money_format” function and replaced it with NumberFormatter instead
2.2
Strip out HTML from any inside shortcodes
2.1.1
Fixed a potential deprecation error: “Methods with the same name as their class will not be constructors in a future version of PHP”
Thanks to Kristina for pointing it out!
2.1
Strip HTML from inside shortcodes
Added a new optional “int” attribute which will format the output in a local currency. So for example, [calculate int=”fr_FR”]15.00[/calculate] will return 15,00
Fixed a potential deprecation error: “Methods with the same name as their class will not be constructors in a future version of PHP”


