Just display content between shortcode brackets

admin2025-06-02  2

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?

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?

Share Improve this question asked Mar 17, 2019 at 17:38 JonJon 3652 gold badges8 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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');
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748798292a313806.html

最新回复(0)