The arithmetic Dynamic Shortcode allows for inline mathematical calculations within text, facilitating operations like addition, subtraction, multiplication, division, and modulo. Ideal for dynamic content, it can process multiple numeric inputs and supports nesting with other Dynamic Shortcodes for advanced calculations.
Syntax
The arithmetic Dynamic Shortcode syntax can take the following forms depending on the operation:
Addition:
{+:<number1> <number2>]
Subtraction:
{-:<number1> <number2>}
Multiplication:
{*:<number1> <number2>}
Division:
{/:<number1> <number2>}
Modulo:
{modulo:<number1> <number2>}
Each operation type requires at least two numeric arguments. However, all operators except modulo can take more than two numbers, allowing a syntax like {+:<number1> <number2> <number3> ...}
for summing multiple values.
Examples
Addition of Multiple Numbers:
{+:10 15 20}
Sums up the numbers 10, 15, and 20, resulting in 45.
Subtraction:
{-:50 20}
Subtracts 20 from 50, yielding 30.
Multiplication:
{*:7 8}
Multiplies 7 by 8, resulting in 56.
Division:
{/:36 6}
Divides 36 by 6, resulting in 6.
Modulo:
{modulo:29 5}
Finds the remainder of 29 divided by 5, which is 4.
Nested Shortcode with Arithmetic:
{+:{acf:price} {*:{acf:price} {acf:sales_tax}}}
Retrieves the
price
field from ACF, multiplies it by thesales_tax
field, and adds the product to the originalprice
to calculate