Shortcode callbacks have to return, not output. So use the following:
function test() {
return '-TEST-';
}
add_shortcode( 'testshortcode', 'test' );
More info: http://codex.wordpress.org/Shortcode_API
If you have to use echo you can also do it this way(useful if there’s a lot of markup & it’s difficult working with strings)-
function test() {
ob_start();
echo '-TEST-';
return ob_get_contents();
}
add_shortcode( 'testshortcode', 'test' );
Related Posts:
- current_shortcode() – detect currently used shortcode
- Get first video from the post (both embed and video shortcodes)
- Implement If-ElseIf-Else-EndIf with short codes
- using html as shortcode attribute
- shortcode outputs first before the page content [duplicate]
- Are php template shortcodes ok?
- Extract attribute values from every shortcode in post
- How to make shortcode to hide selection of text from post or page?
- how to get shortcodes to work inside the text of custom fields
- Shortcode attribute value with dash (hyphen)
- Shortcode content does not show in feed discription/excerpt
- How do I create shortcodes for my wordpress themes?
- Execute shortcode only in another shortcode
- Adding shortcode inside Visual Composer raw HTML [closed]
- Shortcode not working inside html input
- do_shortcode based on _thumbnail_id
- Multiple loops on page only show taxonomy name of first loop
- Add attribute to existing Shortcode
- How to link to a alternative page in CSS
- How to handle a shortcode function directly?
- Turn a snippet of HTML and PHP into a shortcode
- manipulate a plugins shortcode
- How can I get the current user email instead of user ID?
- Shortcodes output in the wrong order
- How to link to a page that has a shortcode?
- Adding short codes from a page’s content on header and hiding the same from page’s content
- Should I cache default WordPress gallery shortcode output?
- How to load shortcode sooner
- Tinymce list of shortcodes button
- Add page title as a javacript variable to specific posts
- WordPress 4.7 Galery shortcode not working
- How to create a shortcode for custom page template
- How to add and submit input fields using a shortcode?
- How can i remove the paragraph from shortcodes content?
- Pass javascript array to shortcode
- WordPress shortcode display as plain text
- Replace / Remove Shortcode after 1st run / post
- Shortcode return $content vs do_shortcode($content)
- Shortcode not working with WordPress updated
- WordPress Shortcode callback function with a plugin
- Can I wrap an unordered list inside a shortcode?
- Problem with multiple shortcode in page template
- Saving post content to database with do_shortcode?
- Is it important to sanitize inputs in a shortcode that will be used in site that only I will post to?
- Shortcode Function not working
- Using shortcode to display array in array
- Add the last viewed post title to a contactform with shortcode [closed]
- Custom recent-posts shortcode’s thumbnail image not in line with rest of code
- Adding a template part as part of a shortcode
- Just display content between shortcode brackets
- How can i share codes on my blog?
- Why does WP display the actual shortcode not the string that’s meant to replace it?
- Getting error on submitting form using Ajax with shortcode
- Check if CTP category taxonomy is set in shortcode
- Using the title of the post in a shortcode
- Hijack WordPress Shortcode attribute
- Turning variable into a value set in shortcode
- How to find specific shortcodes in a post or in a widget and pass them to a variable?
- FontAwesome Shortcode isn’t working properly
- Change variable value for different shortcode attributes?
- Call Shortcode on wp_footer
- How to copy [gallery] shortcode between posts using polylang [closed]
- Shortcode question…. javascript
- Shortcode not displaying video as expected
- How to add a shortcode that creates an adjacent column of text in the content editor?
- Template not loading with get_template_part or locate_template
- How to Display Shortcode’s Content after Short Product Description?
- Check if parent page has child page of certain slug
- Jetpack gallery shortcode with slideshow
- Shortcode atts for WP Query args
- Remove figcation from excerpt
- Shortcode select another dbbase
- How to use code in an editor block?
- return an array with a shortcode
- PHP not outputting the onclick in anchor tag
- Create Button for Shortcode in Text Editor
- Send Mail with link to current_user
- Geoip shortcodes in comments
- Shortcode not interpreted if parameter set
- shortcode atts not working
- do_shortcode for is_page(slug)
- Create shortcode to display specific post in relationship current date
- Add custom shortcodes to the Welcome Mail
- How to handle multiple nested shortcodes with different tags?
- Using shortcode to stop post content from displaying
- Nested WordPress Shortcodes of Different Types
- WordPress Not rendering short code properly?
- Initialize add_action() for every copy of a specific shortcode
- WP_Editor Shortcode Issue
- Shortcode not working in custom post types
- Shortcode or placeholder for theme options page?
- Shortcodes that are created based on user input information
- Remove some tags from shortcodes output? Trying to fix autop
- do_shortcode & render custom field won’t work
- shortcodes inside shortcode to sum values
- is_mobile as shortcode
- How to attach sidebar to shortcode’s output?
- Is it possible to change a shortcode parameter based on a media query?
- IFrame Shortcode plugin – issue
- Wrapping a function in html tag and return?