Displaying shortcodes within posts seems like it should be fairly straightforward. However, due to Wordpress’ shortcode processor the shortcodes will be removed when the post is actually displayed to the user. Fortunately this is an easy issue to resolve.
Lets say for instance that I wanted to display a small piece of code within a formatted code block (provided by the Syntax Highlighter Plus plugin). This code block contains some PHP code as well as the [REMIX] ... [/REMIX] shortcode used by the WP Remix theme. If I attempt to display the code block as-is the shortcode within the code block will be removed as shown below.
// What should be displayed...
$text = str_replace(array('[REMIX]', '[/REMIX]'),
array('', ''),
$text);
// What is actually displayed...
$text = str_replace(array('', ''),
array('', ''),
$text);
The simple workaround for this issue is to encapsulate the shortcode within the same shortcode. An example of this is shown below.
// The format used to display the shortcode properly...
$text = str_replace(array('[[REMIX]REMIX]', '[[/REMIX]/REMIX]'),
array('', ''),
$text);
// What is actually displayed...
$text = str_replace(array('[REMIX]', '[/REMIX]'),
array('', ''),
$text);
It seems like the Wordpress developers would have encountered this issue somewhere along the line. Hopefully they are working on an integrated fix for this issue. If you know of any further information on this issue please let me know so that I may update this post accordingly.
Leave a comment
Comments