I stumbled across this solution a while back; this might be what you are looking for:
I added this to my theme’s functions.php file…
// First, I created a shortcode for a function, that would typically be inserted in to a template file, so that it could be inserted in to a widget.
add_shortcode('myshortcode', 'myfunction');
function myfunction() {
if ( function_exists( 'get_smooth_slider_category' ) ) { get_smooth_slider_category('featured'); }
}
// Then you can add this to allow shortcodes to be used in widgets.
/* Make shortcodes work in widgets */
add_filter('widget_text', 'do_shortcode');
Then I just added [myshortcode] to the text widget and viola; I have a function in a widget.
Related Posts:
- Plugin upgrading: Widget settings
- Simple rich text editor in Text widget?
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- How can I make my custom shortcode work in a Custom HTML Widget?
- Need to create a Theme demo site that features multiple themes
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- How do I add a widget programmatically to a newly created site (WPMU) within a plugin?
- How to place random widgets in the WordPress sidebar?
- Override Widget class in plugins with custom plugin
- Pages with 2 Columns
- Can I ignore caching of a plugin in W3 Total Cache? [closed]
- Why is the unrendered widget number `__i__` showing up in the JavaScript but not in the HTML?
- Custom Widget Creating PHP Exception When Placed In Its Own PHP File
- Remove Widgets in Dashboard
- register child class in another plugin
- Themes VS Plugins [duplicate]
- Changing widget options via the functions.php when there are no hooks
- Conditional Display of Links in Widgets
- Created Widget Not Showing up on Admin Panel
- How do I register a stylesheet inside a WordPress widget?
- Detect if a plugin was included in a certain page
- Flickr plugin that will display photos from multiple group pools? [closed]
- Multisite Widget/Content
- WAMP to XAMPP WordPress transfer
- Widget for adding HTML markup to a page
- The plugin generated 3 characters of unexpected output during activation
- Get post values of form created by widget in sidebar
- Archive – same title for the first two posts
- How to style the RSS wordpress?
- How to display more than one instance for a widget?
- How to add media field to WP_Widget form function?
- changes to widget settings not showing up in individual pages pages until they’re updated [closed]
- Calendar Plugins – Featured Widget [closed]
- Widgets Scripts don’t load – but load when I reload the page
- WordPress plugin subscribe2 not looking the same as before migration
- Setup page on first login on multisite
- How can I inject options into an select tag inside the widget form?
- Add content to footer – above wp_footer
- Custom plugin appears outside of the sidebar container
- How to reorder and display a feed to be chronological?
- Hide certain widgets from specific user roles in admin
- How to add Wrapper Div/container element around WordPress Widget Content
- How do I find out what is in control over a certain part of a website?
- Sidebar widget: Randomly select text from a given set
- Best practice for including plugin output in a template without using shortcode?
- How do I use add_action on custom widget?
- Exclude posts from widget while post is showing on home, single and categories
- Custom widget doesn’t save values from dropdown box
- Register Script in Plugin Widget
- Add Shortcode tag in Widget/Sidebar
- How to create wordpress widget that is fixed position on the home page
- jQuery Click event is not fired at all
- strange shortcode error: does shortcodes requires any dependency?
- All custom widgets are not showing in widget area at the same time
- Widget for specific category
- get_term_meta returns false in widget
- How to set the default value as the saved value once a form of widget is saved?
- My widget won’t update its values when save is clicked
- Widget where it can make changes to the container
- Widget content turns up before title
- Extend a plugin to include a widget option
- Is there a Image Gallery which will load all my posted Images like twitter’s image grid?
- Modify pages widget and make a plugin?
- Listing all sidebars
- Unable to locate inline CSS causing parts of page to be blank
- Table of contents (TOC) plugin is not showing header tag
- Elementor pro page editing gives error There has been a critical error on this website. Please check your site admin email inbox for instructions
- How can I display selected content from a seperate database in an Activity style widget?
- How to fetch WordPress database values in JavaScript widget
- RSS Feed on WordPress showing code (hypertext) in articles titles
- What is the right way to populate a dropdown from MySql?
- Change WordPress plugin widget `id_base` without breaking widget
- Co-author plus: list of posts by authors in the sidebar
- Shortcode generated widget to appear on same line as heading text and button
- How do I keep children of certain parent menus expanded by default on a sidebar?
- Widget logic using woocommerce product category
- How to display widget in front end?
- Widget outputs the value but doesn’t save anything inside the textarea
- How to add styling and script to a custom widget plugin
- WordPress Widget: Is it possible to make the form dynamic without updating?
- Using Widget Logic to place menu on multiple pages?
- Show widget location borders for development
- Cannot access variables within a widget
- How know the “admin” blog from wordpress multisite?
- twitter widget loads properly in all themes except my own theme?
- adding image in the header of my dev widget
- jquery conflict with widget page
- Plugin: Unable to Save the Image Alignment Option to Display in the Widget in the Sidebar
- How to get certain part from widget
- What method should I use for a sidebar widget that reads latest posts?
- pre-upload text and video for the future
- Last article Widget with text preview and more button
- How to add homepage Widget?
- What are the downsides of using bootstrap in plugin development?
- Can’t edit Contact Us form on front page
- Sidebar Slideshow widget with text [closed]
- Content expands beyond its column container [closed]
- Am having issues intergrating this api into my wordpress site, any help please?
- WordPress child theme widget customization – Eduma
- Widget saving but showing “waiting” animation [closed]