• Resolved Argumentum

    (@argumentum0)


    In my tests, variable names cannot contain a dash (hyphen). When a variable has a name with a dash, the variable name (with braces) is printed (instead of its content).

    For example, let’s say I have a snippet called hello:

    <strong>Hello, {variable-name}!</strong>

    When I try to use it like this:

    [hello variable-name="John"]

    The output is this:

    Hello, {variable-name}!

    I don’t exactly need hyphens in my variable names, though. Maybe the variable field could simply turn red (like in the shortcodes with spaces issue) when an invalid character is used (I didn’t tested other possibly problematic characters).

    https://wordpress.org/plugins/post-snippets/

Viewing 1 replies (of 1 total)
  • Hi,

    The variables you define for shortcodes are under the same constraints and restrictions as if you would create a shortcode traditionally in WordPress. So - are not allowed to be used as a shortcode variable in WordPress. Though WordPress allows you to create shortcode variables using _. So if you need a separator character, use _ instead.

    In your example

    <strong>Hello, {variable_name}!</strong>
    [hello variable_name="John"]

    Will work fine.

    WordPress shortcode variables falls under the same rules as ordinary PHP variables. Which would be: “A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores”. Nothing else is allowed.

    Hope this helps.

    Cheers,
    Johan

Viewing 1 replies (of 1 total)
  • The topic ‘Invalid characters in variable names?’ is closed to new replies.