0

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 Answer 1

2

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().

Sign up to request clarification or add additional context in comments.

1 Comment

That was exactly what I needed. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.