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
- Where to put my code: plugin or functions.php?
- Need help setting default setting value for radio button in theme customizer
- How do I use Shortcodes inside of HTML tags?
- Dynamic URL to reference custom PHP files
- WordPress Shortcode and Dynamic CSS
- Prevent multiple counts by same user – WP PostViews plugin
- Creating a WordPress shortcode
- WordPress loop specific thumbnail size
- Theme url in all plugin pages
- How to access function from outside of a class within this class in WP plugin?
- PHP can I add line numbers to file_get_contents()
- Automated Cart Update With Alert Box Each Time
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to sanitize any integer input field in wordpress?
- Adding widgets to my plugin page instead of WordPress dashboard
- How to insert data into database using wp cron job
- Menu jumping when calling it via PHP
- Access Child Class of Plugin Main Class Instance
- get_posts works in the page template but not in a shortcode
- Syntax error in a shortcode function
- How to show an entire post content and not also the excerpt?
- Short code template + ajax
- Commas in Tag Cloud
- Set document title through shortcode plugin
- Illegal string offset checkbox
- Weird fonts showing which are coming from database
- wp_update_post gives 500 internal error
- How to add a PHP scripts into WordPress
- How to give custom roles the capability to edit one Menu instead of every Menu
- widget: input the px value from user and use it as inline style in widget function
- php string inside shortcode does not work
- Limit the number of successful logins
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Problem using explode inside add_shortcode() callback funciton [closed]