0

I am rewriting a theme with shortcodes in the all the posts from the old theme. I searched all the files for the original shortcode function but get no results. So in a vanilla theme the page prints

[shortcode dostuff]content here[/shortcode]

I am trying to get the shortcode to output what is between the brackets, without editing every page on the site, so the page just shows:

content here

I can remove the shortcode with code like

function remove-shortcode() {   return '';}

but then all the content inside the brackets gets removed as well and the page would be blank. I tried function remove-shortcode() {return the_content();} and the page crashes.

What formula will return the content inside the shortcode brackets?

2

I have good news: the answer is simple.

The WordPress Codex concerning Enclosing Shortcodes (like the one you posted here) shows that the shortcode callback has 2 arguments, $atts and $content. You want to work with $content:

function wporg_shortcode($atts = [], $content = null)
{
    // do something to $content

    // always return
    return $content;
}
add_shortcode('wporg', 'wporg_shortcode');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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