WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to put my own function in a widget but it doesn't run. I want to use it everywhere within the widget.

If I could see an example,that'd be great.

share|improve this question
up vote 1 down vote accepted

there are a few way to run a function in widgets:

option 1 - ShortCodes

You can create a custom shortcode and run that function by entering the shortcode into a simple text widget:

//this is to make sure WordPress renders the shortcodes in a text widget
add_filter('widget_text', 'do_shortcode');


function my_function(){
  //do whatever you want

and then simply add [my_short_code] to any text widget to run your function.

Option 2 Plugins

You can use one of the many plugins out there that let you run php in a widget like:

Option 3 Custom Widgets

The last way is to write your own widget using the very simple Widgets API

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.