Because the shortcode must return a string. Avoid using the “echo” function in shortcode.
Instead of doing that:
function my_shortcode_function($content){
echo '<div class="wrap">';
echo '<div class="col">'.$content.'</div>';
echo '</div>';
}
Do that:
function my_shortcode_function($content){
$shortcode_return = '<div class="wrap">';
$shortcode_return .= '<div class="col">'.$content.'</div>';
$shortcode_return .= '</div>';
return $shortcode_return;
}
Or use object buffering:
function my_shortcode_function($content){
ob_start(); ?>
<div class="wrap">
<div class="col"><?php echo $content; ?> </div>
</div>
<?php
$shortcode_return = ob_get_clean();
return $shortcode_return;
}
Related Posts:
- Retrieve multiple values passed to a single attribute in a shortcode
- Display a text message if the shortcode is not found?
- How to use copy() function and paste file in /wp-content/themes directory
- Multiple do_shortcode($content) within one shortcode
- Loading page template into shortcode
- My shortcode is showing up twice
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- do not show web page section when using advanced custom fields pro
- Am I not understanding plugins?
- Using Font Awesome as post thumbnail
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Making Quote Plugin more efficient
- Trigger popup in a php if/else statement
- How can i upload images in an admin page?
- Append HTML Using Shortcode
- Multiple WordPress Menus that will only display all pages
- Plugin CSS not enqueing
- Hide categories that are not used in the post type
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- what is the best practice to add new field to an api route
- Improve page speed loading using CDN and async or defer attribute
- Displaying recent posts on static page with template-part via shortcode
- Redirect to another page using contact form 7? [closed]
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Is There A Way To Make Theme Files Accept Shortcodes?
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- zip unzip attachments in wordpress
- How to add the sidebar to all the pages except the home page? [closed]
- WordPress shortcode returns the data before
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Help Fallback (thumbnail)
- How can I search all plugins for composer’s vendor/autoload.php?
- Action Hook Inside WordPress Plugin Shortcode
- Removed jQuery script from header.php , any problems?
- How to get my [shortcode] rendered on the home page, other pages are fine
- Why in this WordPress theme I can’t see the Main Menu?
- Toolbar Hidden in a Virtual Page
- What is the difference between Null vs Empty (Zero Length) string?
- WordPress navigation wont appear with wp_head
- How to Create custom block for displaying information in content section which act like shortcode
- How to extend SelectControl with data from my theme
- How to change basename url for wp-admin?
- Not able to remove caption shortcode from the content
- How can I prevent a shortcode div from extending beyond its boundaries?
- Display a custom name when the user has no name settle in his account
- Submit remote form to wordpress REST API and save data to custom post type
- Store user form submitted information in post type
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Add a custom link to each image in WordPress gallery
- Gutenberg blocks shortcodes compatibility
- How to return html as a string from php for WordPress
- register dependency css and js inside a plugin class
- PHP code printed into CSS classes
- How to properly escape in ternary operators – Wp Coding Standards?
- Problems with the WordPress loop [closed]
- Shortcode Works for Logged in Users but Not Working for Guest
- WP multisite network plugin fails to see classes loaded with spl autoload
- How to edit the default database of WordPress [closed]
- using a shortcode in a hyperlink
- WP Custom tables query
- Variable ++ in query loop
- Custom plugin with shortcode not working
- Woocommerce Convert existing order to the cart
- Capture the Selected Radio Button Value between two files in wordpress theme
- 404 error on page reload
- How to access function from outside of a class within this class in WP plugin?
- Hiding WordPress Plugin Source Code
- Autogenerate shortcodes from an array of strings
- Remove annoying WP Adminbar CSS
- How to limit the content coming from wordpress shortcodes?
- What is the fastest way to load PHP functions that are only used in one theme template?
- How can i display post loop in table format?
- My Own layout in WooCommerce pages [closed]
- How to return a foreach inside a shortcode
- Page Reloads Before AJAX Request Finishes
- Placing raw HTML inside a WordPress shortcode
- action hook wp_head higher priority as all other plugins/hooks
- Differences when using the the_time and the_date functions
- Exclude posts from homepage having a specified tag
- How do I add text in a shortcode?
- Why is this Ajax not working?
- How do I access the media settings
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Changing the template hierarchy
- How to Insert Shortcodes into Theme?
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- How can I get content inside one shortcode to another shortcode?
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- PHP can I add line numbers to file_get_contents()
- using add_action for a header hook that has an additional parameter
- Template part inside shortcode, unexpected reult
- Shortcode Inside Class Not Working
- Add htaccess rules with insert_with_markers at beginning of htaccess
- Shortcode content output but not in correct place
- How to call function at the bottom of post using plugin?
- is_page “range” for if statement?
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated