I have an existing widget area / sidebar. Rather than adding content to it via Appearance ? Widgets in the Dashboard, I want to inject content into the widget area from functions.php.

Is there hook that allows this?

Thanks :)

2 Answers 2


Yes by using widget_text inject content into the widget area

Add the following code into your function.php file

function widget_content( $content )
    // add $content as you want
    return $content;

add_filter( 'widget_text', 'widget_content', 99 );
  • Great. Thank you, @amitrh. How would I target a specific widget area? I know the widget name.
    – iltdev
    Dec 18, 2014 at 13:07
  • Hey use is_active_widget to target widget area by passing widget id Dec 18, 2014 at 13:17

Also, you can write a function in the functions.php file and call that function via the widget.


function myFunction() {
    //do something here
add_shortcode('wp_my_function', 'myFunction');

//Allow write shortcode in widgets  
add_filter('widget_text', 'do_shortcode');

In the Widget:

Use the text widget, write in the shortcode: [wp_my_function]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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