$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Just display content between shortcode brackets|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Just display content between shortcode brackets

matteradmin10PV0评论

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');

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far