Skip to main content
Arithmetic - Dynamic Shortcodes

Master arithmetic Dynamic Shortcode for executing mathematical operations within content, supporting complex nested expressions.

Updated over a week ago

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

  1. Addition of Multiple Numbers:

    {+:10 15 20}

    Sums up the numbers 10, 15, and 20, resulting in 45.

  2. Subtraction:

    {-:50 20}

    Subtracts 20 from 50, yielding 30.

  3. Multiplication:

    {*:7 8}

    Multiplies 7 by 8, resulting in 56.

  4. Division:

    {/:36 6}

    Divides 36 by 6, resulting in 6.

  5. Modulo:

    {modulo:29 5}

    Finds the remainder of 29 divided by 5, which is 4.

  6. Nested Shortcode with Arithmetic:

    {+:{acf:price} {*:{acf:price} {acf:sales_tax}}}

    Retrieves the price field from ACF, multiplies it by the sales_tax field, and adds the product to the original price to calculate

Did this answer your question?