1

I'm working on a project where I use WordPress admin hooked up with Laravel. I use WP to edit and create posts and Laravel to query the database. I also use shortcodes.

Is it possible to call the do_shortcode() function when saving post content so that the "compiled" version goes into the database and not the shortcode version?

1 Answer 1

0

So I found my answer in the codex.

content_save_pre() is my friend. Here is the usage:

function my_sanitize_content( $content ) {
    return do_shortcode($content);
}
add_filter( 'content_save_pre' , 'my_sanitize_content' , 10, 1);

Haven't tried it yet, it should work I suppose.

2
  • Saving it directly to the content means that shortcode is erased and the next time the post is edited things will get stripped out by security code. Not only that, OEmbeds are't handled, neither are server side rendered blocks. This answers your question, but it does not solve your problem, which I suspect was that you need a way to fetch the fully rendered version of the content. There's a better way to render the content, and a better way to store it for your Laravel app to fetch it.
    – Tom J Nowell
    Commented Mar 11, 2021 at 11:12
  • If you update your question to match your problem rather than asking how to implement a specific solution then someone can post that answer
    – Tom J Nowell
    Commented Mar 11, 2021 at 11:13

Your Answer

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

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