do_shortcode not working, please help!


#1

Hey,

I have a little problem and for the life of me I can’t find a solution. I have a custom box (textarea) in my theme options page and users can insert html & shortcodes that are displayed on the front page. But, I have a user that on his server the shortcodes will not execute. It is just echoing the shortcode instead.

Here’s my code:


<?php echo do_shortcode($data['custom_section_content']); ?>

It’s the firs time this is happening.

Any of you have any ideas?

Thanks and cheers!


#2

could it be on the excerpt possibly?

http://wordpress.org/support/topic/shortcodes-dont-work-in-excerpts


#3

Thanks for the answer but no, it isnt’t in the excertpt. It’s in the theme options area.

Cheers!


#4

oh oh oh! I had this same problem. It was something silly I did… ummmmmmmmmm * searches *

edit: it was this problem I was having: http://themeforest.net/forums/thread/wp-shortcode-contactform7-doesnt-work-in-theme/62795

but for the life of me I cannot figure out how I fixed it. hmmm

edit2: i can only suggest swapping back to the default theme, implement just that bit of code you’re trying to do, and see if it works or not.


#5

Thanks for your reply.

I’ve tried 100 solutions :slight_smile:

The shortcodes work perfect on my local xampp install and all of my servers. I guess they work on 99,9% of the users using the theme. There is only 1 user that sent me this problem. He gave me a test username and pw on his site and I’ve tried almost anything and I’m yet to find a fix. I have never encountered this.

Oh, and the shortcodes work fine in posts or pages. They just don’t work anywhere else when called with “echo do_shortcode”. None of them. It is simply echoing the shortcode.

I think I’m going crazy. I won’ have rest until I find the fix :slight_smile:

Cheers!


#6
Oh, and the shortcodes work fine in posts or pages. They just don’t work anywhere else when called with “echo do_shortcode”. None of them. It is simply echoing the shortcode.

Clearly that points to a problem with the function echo do_shortcode? Does it not?

Just speaking out aloud.


#7

I’m not sure if this will work. But you can give a try:

echo do_shortcode(stripslashes($data['custom_section_content']));

#8

^^Hmm, not looked into that but the above could work…

To me it just sounds like a issue with Wordpress not parsing the shortcodes when called from a function.

I would look into exactly how Wordpress parse the shortcodes from a post or page… A solution might lie there. I’m willing to bet this has nothing to do with the server configuration on this particular client and more to do with how Wordpress parses and converts shortcodes when called directly from that function.

Or there is something wrong with your custom function… or the parameters you are sending it is garbage…


#9

@all: thanks for your answers.

@SaurabhSharma: I did try that last night because he has the “magic quotes” enabled. No luck though.

@iamthwee: I thought about that but I don’t think this is the problem. I’ve tried with the most simple shortcode ever that I’m sure 100% is working for anyone. Still, no luck. And it’s the first user that reports this. I had over 1200 sales and no one ever complained about this.

Cheers!


#10

Maybe he’s running a plugin that’s filtering out the shortcodes. I highly doubt it’s an issue with WordPress Core. Most likely something else in their installation is breaking things.

To be sure, echo the content of $data[‘custom_section_content’] just to be sure it is what you expect it to be.


#11

Hey thanks, didn’t think of that. I just did it and it’s echoing the right thing, still the shortcode won’t execute.

If I echo $data[‘custom_content_section’] I get this for example:

[one_third] TEST TEST [/one_third]

If I echo do_shortcode($data[‘custom_content_section’]) I get the same result. The only plugins are the WP default ones and are both deactivated. Still no luck.

Edit: BTW, is there any other function to run shortcodes out of the query besides do_shortcode? I read something about “apply_filter” but it’s only working for “the_content”.


#12

Just throwing ideas… but assuming nothing is wrong with the shortcode like you have an extra space somewhere, I would try to re- upload the shortcodes.php which is in the wp-includes directory.


#13

Any chance the shortcode is not being registered, or hasn’t been registered prior to running do_shortcode() ?

Try printing the shortcodes before running the function to see if the shortcode is available:

global $shortcode_tags;
echo '
';
print_r( $shortcode_tags );
echo '
';

That should show you what shortcodes are currently registered.


#14

You guys rock. Thanks for all the answers. I’ve managed to fixed it. Still, I don’t know what the problem was although I have a feeling that had something to do with the encoding of the file. I removed the “functions.php” file from the server and added it again from my computer. Now it seems it’s working.

Thanks again.
Cheers!


#15

sweet! glad you got it sorted out :slight_smile:


#16

Nice… So you just re-uploaded the functions.php instead of the shortcodes.php.

Also this guy here:

said he got it working with a fresh install on Wordpress (resetting the server) so maybe it was something to do with encoding like you said?


#17

Guys, I’m having a similar issue.

When using " echo do_shortcode( $options[‘blahblah’]) " the shortcode outputs fine, except it’s at the beginning of the string.

Instead of getting “Copyright 2012 blah blah blah”.

I get “2012Copyright blah blah blah”.

Any ideas why?


#18
jstudios said

Guys, I’m having a similar issue.

When using " echo do_shortcode( $options[‘blahblah’]) " the shortcode outputs fine, except it’s at the beginning of the string.

Instead of getting “Copyright 2012 blah blah blah”.

I get “2012Copyright blah blah blah”.

Any ideas why?

Make sure your shortcode is returning rather than echoing its output. Shortcodes should always return a value if you want them to work as expected.