How to enable shortcodes on my wordpress admin options

Hi guys,

I know that when you want to enable the use of shortcodes in your wordpress text widgets you need to write this code in your functions.php file.

add_filter(‘widget_text’, ‘do_shortcode’);


What I’m trying to find out is how I can use shortcodes with my custom admin options. When I try to use shortcodes inside my admin options page they don’t work.

Any help would be really helpful !

Thanks,
Paz.

Well you can pretty much wrap the do_shortcode() function anytime content is outputted… not sure if it would work. I’m not sure if it would work within your admin area? Good question…

But say you had some text area on your theme options page, I wonder if you could do something like this.

$value = get_option(‘whatever’);

$output = do_shortcode($value);

<?php echo $output; ?>

http://codex.wordpress.org/Function_Reference/do_shortcode

If you’re creating a textarea in your theme options page to allow for the user to input their own content then you’d use something like this.

echo do_shortcode( stripslashes( get_option( ‘footer_content’ ) ) );

do_shortcode allows for shortcodes to be displayed. stripslashes allows for html to be displayed.

You’d just place the above snippet in footer.php.

If you're creating a textarea in your theme options page to allow for the user to input their own content then you'd use something like this.

echo do_shortcode( stripslashes( get_option( ‘footer_content’ ) ) );

do_shortcode allows for shortcodes to be displayed. stripslashes allows for html to be displayed.

You’d just place the above snippet in footer.php.

+1 That makes more sense. Mine was backwards… if you wanted to display the shortcodes in the text area within the admin panel … which makes no sense :wink:

Thanks Themeblvd and matt, I already knew both of the methods. i wanted to know if there is a more “general” way of doing it… Oh well I guess not.

Thanks anyways to both of you!

itsmattadams said

If you’re creating a textarea in your theme options page to allow for the user to input their own content then you’d use something like this.

echo do_shortcode( stripslashes( get_option( ‘footer_content’ ) ) );

do_shortcode allows for shortcodes to be displayed. stripslashes allows for html to be displayed.

You’d just place the above snippet in footer.php.

I tried this method but all I get is the shortcode output, not the rest of the content. Yes, it is a textarea.

<?php if ( isset( $options['leftfootercontent'] ) ) { do_shortcode( $options['leftfootercontent'] ); } ?>

EDIT:

I tried adding “echo” in front of “do_shortcode” and it outputs everything as expected, but the shortcode is the first in line. The output is “2012Copyright blah blah blah”.