Why do_shortcode
doesn't work in a REST call ?
In the example below, do_shortcode
exists, but the shortcode isn't interpreted.
Route declaration
/*
Adding a route with callback is interpret_shortcode function
*/
add_action( 'rest_api_init', function ()
{
register_rest_route(
'test',
'/someContent',
array(
'methods' => 'GET',
'callback' => 'interpret_shortcode'
)
);
} );
Shortcode call
function interpret_shortcode( $data )
{
$content;
if ( function_exists( 'do_shortcode' ) )
{
$content = do_shortcode("[et_pb_text] abc [/et_pb_text]");
}
else {
$content = "do_shortcode is missing";
}
return array('content'=>$content); //Output "[et_pb_text] abc [/et_pb_text]"
}
In a REST call, are we in the same situation as the one describe here about Ajax request ?
do_shortcode
inside thefunction_exists
. Is that a typo in your question or is it your actual code?do_shortcode
doesn't do shortcode.