In the dashboard, I'm using a textarea to get user input. I'd like them to be able to use shortcodes anywhere in that textarea.
Here's my current function:
function slp_getwelcome() {
$slp_welcome = get_option('slp_welcome');
$slp_welcome_sc = do_shortcode( $slp_welcome );
return $slp_welcome_sc;
}
This partially works.
If I have this text in the textarea:
Lorem ipsum dolor sit amet, consectetur [location] adipiscing elit. Donec sit amet quam id eros fringilla.
The above function outputs this:
Abbott, CALorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet quam id eros fringilla.
Where "Abbott, CA" is the proper result of the [location]
shortcode. So the shortcode is called, but it returns at the beginning of the textarea content.
How can I fix this?
Here's the shortcode logic:
function get_location() {
global $post;
$location = strip_tags( get_the_term_list( $wp_query->post->ID, 'locations', '', ', ', '' ) );
echo $location;
}
add_shortcode('location', 'get_location');
A second shortcode reacting the same, despite the use of return
:
function get_service() {
$servive = single_post_title() ;
return $service;
}
add_shortcode('service', 'get_service');