Back to Community

Troubleshooting Common Code Snippets Shortcode Issues

49 threads Sep 9, 2025 PluginCode snippets

Content

Using shortcodes with the Code Snippets plugin is a powerful way to add dynamic functionality to your WordPress site. However, users often encounter a few common problems that prevent their shortcodes from working as expected. This guide covers the most frequent issues and their solutions.

1. Shortcode Outputs Raw Text Instead of Executing

This is one of the most common issues. You place a shortcode like [code_snippet id=4] on a page, but instead of seeing the dynamic result, you just see the shortcode text itself.

Why this happens: This is almost always a caching issue. Many WordPress sites use caching plugins (like LiteSpeed Cache) or server-level caching to improve performance. These systems save a static version of your page, which means PHP code, including shortcodes, isn't executed on every page load.

Solution: Clear your site's cache after updating a snippet. If the problem persists, you may need to configure your caching plugin to exclude the specific page where the shortcode is used from being cached. The 'Code Snippets' team suggests using the sgo_exclude_urls_from_cache filter for the SG Optimizer plugin, for example.

2. Unwanted Paragraph Tags and Line Breaks in Output

Your shortcode works, but it's wrapped in extra <p> tags or has unexpected line breaks, which can break your layout.

Why this happens: WordPress's automatic formatting system, wpautop, is designed to convert line breaks into paragraphs. It can sometimes interfere with HTML output from shortcodes.

Solution: When inserting a snippet's shortcode, remove the 'format' attribute. For example, use [code_snippet id=33 php] instead of [code_snippet id=33 php format]. The 'format' attribute explicitly tells WordPress to apply paragraph formatting, which is often not desired for HTML snippets.

3. Shortcode Attributes Not Being Passed Correctly

You create a shortcode that accepts parameters, like [my_shortcode color="blue"], but your function doesn't receive the values.

Why this happens: The shortcode callback function must be written to accept the $atts parameter. A common mistake is defining a function that doesn't accept any parameters.

Solution: Ensure your shortcode function is properly defined. Here is the correct structure:

add_shortcode( 'my_shortcode', function ( $atts ) {
    $args = shortcode_atts( array(
        'color' => 'red', // default value
    ), $atts );

    return "The color is: " . $args['color'];
} );

4. The "Evaluate Shortcodes" Checkbox Unchecks Itself

You try to enable the option to evaluate shortcodes within an HTML snippet, but it automatically disables when you save.

Why this happens: This typically occurs if there is a syntax error or an unsupported shortcode within the snippet's content that prevents it from being saved with the setting enabled.

Solution: Carefully check the code in your HTML snippet for any errors. Temporarily remove any complex shortcodes to see if the setting will save. If it does, you know the problem lies with the shortcode you removed.

5. Basic Shortcode Mistakes

Sometimes the issue is a simple typo in the code.

  • Missing href attribute: A shortcode returning a link like <a "https://example.com">Link</a> will fail. It must be <a href="https://example.com">Link</a>.
  • Echoing instead of Returning: A shortcode function must return its output, not echo it directly. If you need to output complex HTML, use output buffering:
    add_shortcode( 'my_shortcode', function () {
        ob_start(); // Start output buffering
        ?>
        <!-- Your HTML content here -->
        <?php
        return ob_get_clean(); // Return the buffered output
    } );

By following these troubleshooting steps, you should be able to resolve the majority of shortcode issues encountered with the Code Snippets plugin.

Related Support Threads Support