The output from a shortcode should be returned, not echoed. Echoing output in a shortcode will have unexpected output like you are seeing. the_widget()
echos its output which is causing the issue. Unfortunately there is no similar function for returning the wdget output.
Luckily you can make use of a output buffer to overcome this issue. You can try something like this : (CAVEAT: Untested)
function show_custom_widget() {
ob_start();
the_widget( 'YOUR CUSTOM WIDGET' );
$contents = ob_get_clean();
return $contents;
}
add_shortcode( 'custom-widget', 'show_custom_widget' );
Related Posts:
- Shortcode from a widget is wrapped in unwanted element
- How can I whitelist only specific shortcodes for processing in text widgets?
- When to use which plugin output method?
- Custom shortcode in widget forced to top of widget
- Shortcode in Text Widget not working
- Inserting shortcode [stream /] into a Text widget
- check for shortcode in post/pages AND widgets AND template files
- the_widget() and widget’s ID
- How the widget can be run by shortcode
- How do i display the built-in gallery inside a widget?
- Shortcode displays always first. Once again
- Create a widget to use shortcode?
- Check if the current shortcode is being used in a widget
- Allow shortcode for custom widget
- Shortcode not working in widget
- call widget from within shortcode
- Transform php shortcode into a widget [duplicate]
- Can I use widgets & shortcode if I need to return an array?
- page url in shortcode
- How do I get shortcode, widget and template tag CSS to load in the head only as required? [duplicate]
- Where to put my code: plugin or functions.php?
- WordPress 3.8 – Dashboard 1 Column Screen Options
- Executing Javascript When a Widget is Added in the Backend
- Get number of widgets in sidebar
- Enabling jquery when dragging available widget to sidebar area
- How to display custom widget anywhere
- Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?
- PHP Coding Standards, Widgets and Sanitization
- Different widgets on different page templates?
- Widgets not displaying in theme customizer
- Register multiple sidebars
- Where to get the unsaved list of widgets in customizer?
- Reorder dashboard widgets
- How do I create a widget that only allows a single instance?
- Using tabs in admin widgets [closed]
- Save/update widget outside admin panel [closed]
- Creating your own widgets: using cache?
- Removing custom widget area WordPress 4.4 [closed]
- Insert widgets after theme installation [duplicate]
- Replace dashboard widgets with banner ad
- Widget code is not working on WordPress.com Hosted Blogs
- Show tags selection similar to category selection in WordPress
- Why can’t I see “Widgets” in my Apperance menu?
- Dynamic sidebar based on category
- Show posts from one category with thumbnail and description on latest
- How to pass data from page to widget functions?
- Adding a rich text editor to a widget – specifically CKEditor
- Enqueue script/style if certain widget has certain value
- How to display/register widget only on post pages in custom plugin
- Is it possible to display tag cloud widget by category?
- Widgets not saving values
- Widget page is missing from menu and default widgets are not showing
- wp_editor in widget breaks after save (no buttons and visual tab broken)
- How to use a dropdown to populate a list of post from CPT
- Registering a stylesheet inside my WordPress widget
- How to position custom dashboard widgets on side column
- WordPress widget title coding
- Text Widget in Footer for just 1 page template
- How to change color of registered widget areas in admin?
- Filter Text from sidebar widget?
- How to filter widget(s) based on a specific category landing page
- How do I remove/reset all current widgets from the database?
- Search transients through widget
- what is the difference between these two types of widget form method
- Change the background color of my theme widgets
- Shortcode inside text widget do not call enqueue style
- Output column number according to active sidebars
- Why isn’t my custom widget outputting any content?
- Make single widget area top level in 4.0 Customize Panel
- Instance not inserting data for widget
- Sidebar widgets – dynamic CSS : problem with widget-title
- widget not displayed
- Dynamically creating multiple widgets from Mustache templates
- changing the style of sidebar
- Vimeo Feed gived dead link with RSS widget?
- Preset Widgets ONLY after site is initially created
- Is it possible to add a preview to custom developed Widget?
- How to enable [archives] short code
- Where does the removing of widget through appearance – customize take affect
- Widget editing returns JSON response error
- Allow users to give a dashboard widget a custom name using ACF
- How to change widget title in wordpress version 5.8.1?
- why the code html apear in this widget in footer
- Why does my $instance within a custom widget return empty (undefined index)?
- My widgets do not save
- How to move widget area to another section in WordPress Customizer
- I cannot customize custom widgets anymore after moving WordPress website
- How can I only show a widget prior to a specific date?
- Add sidebar in inner pages
- Widget Areas Still Appearing in WP ADMIN When They Shouldn’t
- Dynamic Width of Widgets
- How to filter the widgets like calendar and archives based on category in WordPress
- My Email Newsletter plugin will not configure when I try to import the widget
- Imported blog page layout messed
- Widget options – where to put them?
- I add some js files from a plugin to a specific location
- Include widget within newsletter template?
- My understrap-child theme doesent have a head.php, footer.php
- How do you submit a widget for the wordpress directory?
- do_shortcode autommatic content generation