Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been playing around with ajax in wordpress and I've gotten my efforts to work on both back and front-end without too much trouble, however I've run into a problem getting post shortcodes to run when loading post_content to the front-end.

Here's what I've noticed:

apply_filters( 'the_content', $content );

..will run but it only wraps my shortcode in <p> tags, the way it does in the admin.

do_shortcode() will work when using [gallery] or other native wordpress shortcodes, but not the one i've registered in my plugin.

My plugin shortcode does however run in the normal wordpress post page (not ajax).

Having read about this, I'm aware that admin-ajax.php has WP_ADMIN set to true and so I think that what happening is that apply_filters( 'the_content', $content ); runs differently depending on whether is_admin or not.

Either that or native shortcodes and plugin shortcodes add_shortcode() are registered differently and not accessible in the same places.

Does anyone have any insight on what's going on here?

Much appreciated.

share|improve this question

closed as not a real question by toscho Jul 12 '12 at 22:48

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Can you post the actual code you're having trouble with? Specifically the ajax callback and the portion of the code where you're calling add_shortcode() to register your custom shortcodes. –  chrisguitarguy Aug 27 '11 at 18:04
    
Yeah, I'm thinking that most likely you're adding the shortcodes on a hook that doesn't fire in an admin page. Would be helpful to see how you register it. –  goldenapples Dec 7 '11 at 19:30

1 Answer 1

How you are applying a filter is wrong. You need to bind a function to the filter, but you are providing a variable.

function my_filter( $content ) {
    return $content . 'My added code';
}
add_filter( 'the_content', 'my_filter' );

You should add the code like this, this should work.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.