Shortcodes need to return data, not echo it – use output buffering to capture the output of the include and return it:
function related_category_sidebar() {
ob_start();
include WP_PLUGIN_DIR . '/sabai-directory/assets/templates/template_related_category.php';
return ob_get_clean();
}
Then you will also need to do as Charles suggested and enable shortcodes for text widgets:
add_filter( 'widget_text', 'do_shortcode', 11 );
Related Posts:
- How to check if a shortcode is being executed in a widget or post
- gutenberg widget outputting paragraph marks
- Why are Shortcodes Disabled in Widgets by Default?
- List monthy archives for specific year with wp_get_archives
- add widget to page content (using shortcode)
- How to add shortcode to html widget
- Shortcode inside text widget do not call enqueue style
- Use atributes of shortcode in get template part
- How to completely prevent WordPress from destroying/modifying my shortcode outputs?
- do_shortcode autommatic content generation
- Add widget/shortcode to sidebar OUTSIDE of the theme
- Conditionally Loading JavaScript/CSS for Shortcodes
- shortcodes output before content [duplicate]
- WordPress adds br in between my shortcode
- Shortcodes, HTML tables, and multiple rows
- Does a shortcode with a single attribute have to use an array?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How navigation works in custom loop within shortcode?
- Use [shortcode=”value”] instead of [shortcode att=”value”]?
- I dont want to show shortcode in tag
- Post loop created via shortcode not displaying shortcode in content
- Pass shortcode variables to template
- Is it possible to add a repeater field to TinyMCE’s option window?
- Shortcodes: Pros and Cons
- esc_attr not working in shortcode
- Raw output (preventing wpautop)
- Can’t understand $atts in functions?
- Are .MP3 files with capital letter extensions allowed in [audio] shortcode?
- How to handle shortcodes when using the JSON API
- Are shortcode functions applied while rendering the content, or are they executed and stored with the post content?
- How to parse this shortcode?
- Get Posts shortcode plugin and meta_query?
- Shortcode parsed incorrectly because of heredoc
- Shortcode is running in page editor
- Creating shortcode with parameter
- Video Shortcodes not working in WordPress
- Check if the current shortcode is being used in a widget
- How to force that styles are enqueued in the header?
- Create shortcode in WordPress, using one variable in 3 functions?
- Edit shortcode in post content programatically
- Adding javascript actions to words in post content
- How to change to local video player on shortcode ultimate to video.js?
- My shortcode does not call the function
- Shortcode not showing anything
- return unformatted content in encosing shortcode
- How to display Feedburner subscription count as plain text via a shortcode in post/page editor of my WordPress blog?
- How to create an incremental list using shortcodes?
- Shortcode in my childtheme is not working
- How to Make Archive ShortCode
- Are Shortcode Attributes Always Passed As Strings?
- Show form per shortcode
- wp_editor not rendering the shortcode
- Default WordPress shortcodes not working?
- How to make this shortcode work for post content wordpress [duplicate]
- Pass fileurl parameter into shortcode from Advanced Custom Fields
- stop WordPress removing shortcode from content [closed]
- caption shortcode using image alt as caption
- Shortcode arguments to another shortcode
- Sanitize or treatment of string in editor via shortcode
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Execute Shortcodes when submitting post
- Substituting value via shortcode
- Can’t render shortcode when html tag contains hyphen
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- Not to escape a text
- Color on Shortcode insert that creates a button
- shortcode doesnt work on excerpt
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- Pagination for custom posts loop
- Shortcode is not showing content when placed in editor (post_type = page)
- Modify [caption] shortcode so and are not used?
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- How to Call Related Post based on Categories Inside Post Content with Shortcode?
- How to strip header tags & shortcodes from the_excerpt()
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- Cannot modify class property from shortcode handler function
- Reusable Dynamic Taxonomy Shortcode
- How do i remove Business feeds Shortcode fatal error
- Can’t place endwhile in the loop properly in a shortcode
- How to reduce the image size inside an icon? [closed]
- How to insert visual compser post grid shortcode in a custom page template? [closed]
- latest posts shortcode with image
- Shortcode tags appear on mobile themes
- Video shortcode inside tabs shorcode NOT working
- Manipulated shortcode output
- Where is escaped the shortcode?
- Str_replace using shortcode with multiple changes
- Changing layout of defaul gallery output to masonry
- shortcode change variable base on user
- WordPress do_shortcode first iteration
- page url in shortcode
- Add a short code to a plugin
- How to remove https:// from shortcode generated url
- How to enable on custom shortcodes
- Nested ShortCode works inside the_content, but not outside of it
- How to edit a widget code?
- Why does my shortcode query not working with search term
- How to use multiple values in “Shortcode”? [closed]