Add LaTeX Math Symbols and Equations in WordPress

How to write LaTeX Math Symbols and Equations in WordPress

If you are a course creator or someone who is writing maths questions on WordPress, the most common problem is that you can not add LaTeX Math Symbols and Equations in WordPress directly; you need to install a LaTeX plugin to make those symbols and equations work.

To avoid extra plugins that might end up in a conflict with your site, like we experienced for one of our clients, as she was using LearnDash LMS so we installed the plugin, and it didn’t work. Still, the good news is that we have really simple code that will allow you to add LaTeX Math Symbols and Equations quickly.

Step 1: Paste this code in functions.php

You can find function.php in the following path. Simply go to Appearance>> Theme Editor >> Function.php

Elementor Pro

(Prefer a child theme or the Code Snippets plugin to keep changes update-safe.)

function render_latex_inline($atts, $content = null) {
    $content = shortcode_unautop($content ?? '');
    $content = trim($content);
    return '<span class="latex-math">\\(' . $content . '\\)</span>';
}
add_shortcode('latex_inline', 'render_latex_inline');

function render_latex($atts, $content = null) {
    $content = shortcode_unautop($content ?? '');
    $content = trim($content);
    return '<div class="latex-math">\\[' . $content . '\\]</div>';
}
add_shortcode('latex', 'render_latex');
  1. Use the shortcodes in your WordPress editor (Classic Editor, Block Editor, or Elementor text widget).
Inline math shortcode:
[latex_inline] ... [/latex_inline]

Display math shortcode (new line, centered):
[latex] ... [/latex]

Example:

  • Inline math:
    [latex_inline]E=mc^2[/latex_inline]
  • Display math (on its own line):
    [latex]\int_0^1 x^2 \, dx = \tfrac{1}{3}[/latex]
Example 1 – Inline Math

Einstein’s famous formula is

𝐸 𝑚 𝑐 2 Emc 2

Shortcode used:

Einstein’s famous formula is [latex_inline]E=mc^2[/latex_inline].
Example 2 – Display Equation

The quadratic formula:

LaTeX Math Symbols and Equations

Shortcode used:

The quadratic formula is:
[latex]x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}[/latex]

Final Thoughts

Adding LaTeX math in WordPress is simple with shortcodes and MathJax, letting you display clean, professional formulas in posts, lessons, or course content.

At LMS Crafter, we build and optimize WordPress LMS platforms like LearnDash, BuddyBoss, and MemberPress. Need help with LaTeX setup or a custom LMS? Get in touch.

👉 Try the shortcodes above and make your math content shine!

Leave a Reply

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