Adding shortcodes allows users to add dynamic content to areas of the site that would not have otherwise accepted them. The text widget is a general purpose widget area. Traditionally, WordPress forbids adding shortcode content here. The workaround presented here allows users to make this modification.
What are shortcodes? Shortcodes are little code snippets that perform specific functions. Usually, shortcodes are coded into plugins to allow you to add special code to text areas that would not normally be able to accept PHP code directly.
In this guide, we will get the shortcode we want, add a text widget, and add our shortcode to the text widget.
Getting the Shortcode and Adding Widget
The first step is to get the shortcode you want to use and a text widget. In this example, we’re using a Ninja form.
- Click WPForms.
- Copy the Shortcode for the Information Request Form (available in the second column).
- Click Customize.
- Click Widgets.
- Choose the area to which you are adding the widget.
- Click Add a Widget.
- Choose Text.
- Title the widget and add the shortcode.
- Click Save & Publish
Editing the functions.php file
This step involves editing one of your theme’s source files. This is an advanced step. It can also be hazardous if you are unfamiliar with the structure of WordPress themes.
This is why it would be best to take this step in a WordPress child theme. This way, updates made to the base theme will not wipe out the changes we are about to make.
Before beginning the steps below, copy the following code:
add_filter( 'widget_text', 'shortcode_unautop'); add_filter( 'widget_text', 'do_shortcode');
- Click Settings.
- Under Settings choose BoldGrid.
- Find the option for Reorder Admin Menu and uncheck Use BoldGrid Admin Menu System.
- Click Save Changes.
- Click Dashboard to refresh the page.
- Hover over Appearance and click Editor.
- On the right column, click Theme Functions.
- Paste the code copied above at the bottom of this field.
- Click Update File.