How to add custom code and shortcode definitions

As there have been a few posts where questions around this came up, I thought it may be useful to show the four most common ways you can add custom code that work well with Cwicly.

1. Child theme functions.php

  1. Download the child theme and install from here (only do this for new websites unless you know how to transfer your theme customisations to the child theme): dashboard - Add child theme & make links obvious - #9 by StrangeTech
  2. Edit the functions.php file and add your custom code

2. Cwicly custom code

  1. Go to Cwicly Settings

  2. Add your custom code in the Custom Code area

3. Code Snippets plugin

  1. Install and activate the Code Snippets plugin
  2. Add a new snippet
    Screenshot 2023-06-25 at 11.45.12
  3. Add your custom code to it

4. Cwicly Code block (in post, page or template)

  1. Ensure you enable the use of code blocks in the Role editor as per the Cwicly documentation
  2. Add a code block to the post, page or template you want it to be used on
  3. With the code block selected, insert your code into the appropriate field in the inspector panel

Depending on your requirements and ways of working, one method may be preferred.

For example, some developers may use the Code Snippets plugin on all of their sites and so the quick import and export may become useful.

On the other hand, if keeping the number of plugins to a minimum is a priority, then using the built-in Cwicly methods maybe preferred.

The key factor is to ensure the code is available for the context you want to use it. If it is only going to be used on a single page, then using a code block on that page may be a good approach. If the code must be available on all pages, then either placing it within a globally used page template or using the code snippets / custom code / child theme functions.php become the applicable choices

Hopefully this will help those of you learning how best to use Cwicly more easily use custom code on your websites.