0
votes

I'm creating a theme and i want the user to be able to use shortcodes.
Right now it outputs [the_shortcode] and I think I know why but don't know how to fix it.

I load the content of the page not in the conventional way. Preferably the way is to load the_content() function. But the way my template is designed it loads content based upon placement in the hierarchy of pages.

So a parent has a different look then a child.

To do this I load the content with a foreach loop and echo out $grandchild->post_title. The page being a grandchild of a parent.

Now the way to fix this, according to the internet, is to use the apply_filters() function.
The function expects two parameters and I have no clue on how to fill them:

function apply_filters( $tag, $value )

This is my function for the shortcode:

function output_function(){
    return 'Knees weak, arms are heavy';
}
add_shortcode('output', 'output_function');

The shortcode is placed in a page post like this: ['output']

Any thoughts on how to output page content through the filter?

1

1 Answers

2
votes

What you want is the_content

$content = 'some string that has a [output] shortcode';
echo apply_filters('the_content', $content);

This filter will make sure all $content is parsed like the WordPress editor.
The same like the_content().