• Resolved joop99

    (@joop99)


    I installed the free version of Code Snippets. Initially I wanted to add my own argument. There is an option ‘ Evaluate additional shortcode tags’ but if I enable it, then save the snippet – this option gets reverted always. There is no way to persist it to support that.

    Then I tried to do without additional attributes. In fact I want to get a scalar result (a number) and add that in between text. Getting the scalar works – but the code snippet always applies ‘ Add paragraphs and formatting’. There is no way of unselecting that ;-( I also tried to use the attribute format=false with my short code but that is ignored.

    So I have 2 problems:

    • is it possible to use my own shortcode attributes with the free Code Snippets plugin?
    • is it possible to disable the formatting?

    I hope someone can point me in the right direction.

    Thanks,

    Joop

    • This topic was modified 3 years, 1 month ago by joop99.
    • This topic was modified 3 years, 1 month ago by James Huff.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi Joop,

    The checkboxes and options on that page aren’t saved anywhere – they just change what appears in the shortcode on the page that you can copy and paste. If you uncheck the box and then copy the generated shortcode, additional formatting won’t be applied.

    You can definitely pass additional attributes – you just need to include them in the tag directly. For example, if the shortcode tag you’re given looks like this:

    [code_snippet id=42 php=true]

    Then you can just include whatever other attributes you need to as part of the tag, e.g.:

    [code_snippet id=42 php=true result=12]

    And then use this in your snippet like this:

    The result is <?php echo esc_html( $atts['result'] ); ?>.
    • This reply was modified 3 years, 1 month ago by Shea Bunge. Reason: clarification
    Plugin Author Shea Bunge

    (@bungeshea)

    In version 3.4, I added the ability to just use additional attributes as regular variables in the snippet.

    For example, you could use a snippet shortcode like this:

    [code_snippet id=42 php fruit="Apples" age=25]

    … and then access those attribute values within the snippet code:

    My favourite fruit is <?php echo esc_html( $fruit ); ?>
     and I was born in <?php echo date( 'Y' ) - intval( $age ); ?>.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Code Snippet fails with attributes’ is closed to new replies.