I have a shortcode [table id=table /]
I want to do something like this <?php echo do_shortcode('[table id="'.$post->post_name.'"/]'); ?>
I want the slug to appear as the table id.
What am I doing wrong?
I have a shortcode [table id=table /]
I want to do something like this <?php echo do_shortcode('[table id="'.$post->post_name.'"/]'); ?>
I want the slug to appear as the table id.
What am I doing wrong?
Comments are closed.
Given that you mentioned in the comments that you’re trying to use this shortcode in a widget – widgets don’t parse shortcodes by default.
To make most widgets parse shortcodes (most being those with text fields that apply the
widget_text
filter), you can add the following to your theme’s functions.php:You can then refer to this shortcode directly in your widget text like you would expect you can:
EDIT:
If you have any trouble running shortcodes that are on their own line, it may be because they get wrapped in
<p></p>
tags automatically by WordPress. To stop this happening, add this filter before the one added above:The shortcode_unautop() function simply stops shortcodes from being wrapped in paragraph tags like is WordPress’ default behaviour in most text fields.