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
- Where to store PHP files created by plugin / themes
- Should I use spl_autoload_register() in my plugin?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to find the output of contact form 7 shortcode? [closed]
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- Custom filter in admin edit custom post type responding with invalid post type?
- How to access global variable $menu inside a class function
- How to upload a file to a folder named after the user_id via plugin
- Can’t access variable outside for loop
- add custom link to wordpress media gallery modal
- adjust section according to country?
- Two queries for a WP_User_Query search work perfectly apart, but not together
- How to Reference/Echo Variable from Another PHP Function
- Replace shortcode in substring
- How to use html inside a functions.php code?
- plugin add action hook is not working :
- Hooks for post saving make a post-new.php to load latest post’s data
- Using flickr api in custom wordpress plugin
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- Adding image upload in tag section – WordPress plugin development
- Display logged in user name and lastname on page
- How to Remove Theme Style CSS inside Custom Plugin?
- Conditional formatting on data fetched from MYSQL
- How do I remove an action hook inside a class that is called by another class?
- Display current user metadata on WordPress page
- Add Shortcode to ::before class
- Parsing webhook from Shopify in WordPress
- Submit to itself don’t work
- perform mathematical operation on shortcode
- WordPress / PhpStorm / XDebug and plugin_dir_path issues
- Do_shortcode on PHP file outside theme ALMOST works
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Too few arguments at registering new templates in my plugin
- I want to lists posts in wordpress to nearest location entered by the user
- How to edit a widget code?