@ Richard
RE: I wonder if you could reccommend a good tutorial on the syntax to be used in shortcodes particularly with reference to single and double quotes and how what they do and how to use them.
I did a web search on this topic an actually came up empty handed. Sorry, that I am unable to recommend a tutorial!
I do have this tutorial I wrote long ago:
I do not mention anything about quotes. Something I definitely can add.
RE: Could you give some examples of trouble you had with quotes?
The are actually very few rules, off the top of my head:
- Quotes are optional for single value options such as an ID number, true or false. When an option can take multiple words as values, quotes are necessary. This way WP knows that they are one value for a single option vs multiple options.
- DO:
[shortcode-tag option=1] - DO:
[shortcode-tag option=true] - DO:
[shortcode-tag option='true'] - DO:
[shortcode-tag option='one value for an option'] - DO NOT:
[shortcode-tag option=one value for an option]. WordPress will read this as valueoneforoptionthe remained of of words will be process as options with no value. And, a properly coded shortcode will discard those as invalid options.
- DO:
- Not a rule, but recommended… Always quote the option values even though in some cases they are not required to be quoted.
- DO:
[shortcode-tag option='true']even though[shortcode-tag option=true]is valid.
- DO:
- Not so much a rule, but a suggestion… Stick to a single quote type for you option values. Meaning, stick with single quote style. Meaning, use either only single quotes
'or double quotes".- DO:
[shortcode-tag option='value'] - DO:
[shortcode-tag option="value"] - DO NOT:
[shortcode-tag option='value"]. Notice the different quotes being used.
- DO:
- When using a single quote (an apostrophe) within an option value, you must use double quotes:
- DO:
[shortcode-tag option="value's"] - DO NOT:
[shortcode-tag option='value's']. If you have a shortcode with multiple option value pairs this can really break the ability of WordPress to match the proper options and values leading to a broken shortcode at worse to unpredictable results at best.
- DO:
- Do not use fancy quotes, always use straight quotes when quoting the option values. This is a fancy single quote ‘ and this is a fancy double quote “. Outside of shortcodes WordPress will convert the straight quotes to be fancy quotes. To use straight quotes, you do not need to do anything special, just use the quotes on the keyboard as you normally would.
- Never copy/paste shortcodes or their option value pairs from a web page and paste them into the WordPress Visual Editor. In all likelihood you will be pasting in fancy quotes which break the ability of WordPress to properly read the shortcode. The underlying HTML of the source page will also be pasted into you page. This mean you will see a shortcode that looks right, but is actually not a shortcode at all with can not be properly read by WordPress.
- Always add and edit shortcodes using the Text tab and not the Visual tab in the WordPress Editor. This will help ensure that fancy quotes are not used and no HTML is pasted from a web page.
- NOTE: In the new WordPress Block Editor, use the Shortcode block.
All this said
Connections, when saving a page/post will actually attempt clean and repair the shortcode correcting some of the above, but it is basic and does have limitations. This was one of the best things I have ever added to Connections because support related issues in regards to shortcodes went way down.
Hope this helps, let me know!
-
This reply was modified 7 years, 4 months ago by
Steven Zahm.
