Back-end Configurations
- In the All Snippets section, click on the Add New button to add a new snippet.
- Or navigate to the WordPress Admin Dashboard → Post Snippets → Add Custom Code.
- The add new snippet page will open.
Add a Snippet Title
- Enter a Snippet Title that will help you identify the snippet in the All Snippet page.
Code Editor
- This is the block of Text, HTML or PHP code which is inserted in the post or used as a shortcode.
- Type in your code or text in the Code Editor.
- If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets in the Code Editor.
Add Variables
- If you want to enter predefined variables, you can reference them from the Variables field.
- The Variable field is a comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.
Note: Assign your variable in “” (quotes) in code editor, for example: $variable = “{yourVariable}”.
Make a shortcode
- The Shortcode checkbox is the identifier, and it is required to make the appearance of the snippets on the page/post.
- When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode in the post editor window. The advantage of this is that you can insert a block of text or code in many places on the site, and update the content from one single place.
- It can still be added directly in the Block Editor if this option is not selected, provided that its status is Active.
- The name to use the short-code is the same as the snippet title (spaces are not allowed). When inserting a short-code snippet, the short-code and not the content will be inserted in the post.
- If you enclose the short-code in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don’t use it in the variables field.
- The Shortcode can be found in the Actions panel located on the right hand side of the page.
- It is displayed after Saving the snippet.
Make a PHP code
- Snippets can optionally also be evaluated as PHP Code by enabling the PHP checkbox.
- Any snippet variables will be replaced before the snippet is evaluated as PHP code.
- Also note that a PHP snippet doesn’t need to be wrapped in <?php ?>.
- After clicking on the PHP Code checkbox, the code will be automatically wrapped in <?php ?> in the Code Editor.
WPTexturize
- Before the shortcode is outputted, it can optionally be formatted with WPTexturize to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.
- Click on the WPTexturize checkbox to enable it.
Action Panel
- The Actions panel is located on the right hand side of the page.
- It contains the Download Snippet button. This button allows you to download the previous snippet version from the cloud.
- It contains the Upload Snippet button. This button allows you to upload the current snippet version on the cloud and update the previous snippet.
- You can also duplicate the snippet. Click on the Duplicate Snippet button if you want to duplicate it.
- Shortcode of the snippet can be found in this panel if the shortcode checkbox is marked.
- You can also change the status of your current snippet from the Status dropdown menu. Change it between Active and InActive.
Groups
- If you want to add your snippet in a group, select a group from the Groups panel.
Add Description
- You can add an optional description for the Snippet.
- Type in the description for the snippet in the Description.
- After setting the snippet, click on the Save button to save the snippet.
- Your snippet will be displayed in the snippet table in the All Snippets section.