PHP code won’t run inside of a text widget. There are plugins that will let you do that, but this type of thing is strongly discouraged.
Add this code to your functions.php file, or better yet, make it a simple little plugin:
// Enable the use of shortcodes within widgets.
add_filter( 'widget_text', 'do_shortcode' );
// Assign the tag for our shortcode and identify the function that will run.
add_shortcode( 'template_directory_uri', 'wpse61170_template_directory_uri' );
// Define function
function wpse61170_template_directory_uri() {
return get_template_directory_uri();
}
To use it in the admin, add the shortcode [template_directory_uri]
to your text widget, and the template directory will be output e.g.
[template_directory_uri]/images/image.jpg
Related Posts:
- Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?
- Get page IDs based on which template they are using?
- Different widgets on different page templates?
- How to check if searchform.php is being included as widget?
- How to change plugin`s template (view) correctly?
- How do I create a template page with a specific widget as the content?
- How should I add a “widget” like element?
- WordPress 5.8 : display new widget
- How do I enable the admin form for a custom widget that is called in a sidebar template, not to widget area?
- How to create sidebar from “scratch”?
- Correct way to add a block element to sidebar layout
- My understrap-child theme doesent have a head.php, footer.php
- Hide specific categories from category widget
- Can a widget in the Customizer be “single-use” (i.e. disabled after 1 instance has been added)?
- Does the number of widgets installed affect website performance?
- Why is the $old_instance needed for the widget update function?
- How to add color picker to widgets?
- How to delete cached transients from a widget instance properly?
- What is this instance variable doing in the Widgets class
- Remove All Widgets from Sidebar
- How do I use the control callback when creating a simple dashboard plugin
- Unregistering a Sidebar in Child Theme
- Problems with the sidebar args and wp_list_bookmarks
- Ban certain widgets from certain sidebars
- is_active_sidebar() Always Returns False
- Different rss feeds in a single dashboard widget
- How could a Widget behave differently depending on sidebar
- Count widgets in position and set class
- iris color picker in widget – click event doesn’t fire when initially when widget is first created
- Custom widget using get_categories select menu dropdown
- Widget options get
- Insert custom content before widget title/after widget opening tag
- Custom Menus, Widgets & Conditional Statements
- Dynamic widgets
- How do I stop a widget from displaying on mobile site?
- cannot drag and drop widgets since wordpress 3.2.1
- Show widget when not using SSL
- How/where is the global variable $wp_registered_widgets filled?
- Converting a WordPress widget to a block
- Change recent posts widget title
- Hide all Dashboard Widgets (not remove)
- Widget modifications in a child theme
- Making footer widgets responsive
- Form link throwing website to main language
- Is there a way to extend the default image widget into a new custom widget and add additional fields to it?
- Conditional Tags Based on Previously Viewed Posts
- Make page jumps in widget
- Widget without DIV wrapper
- Widgets not displaying since 4.3
- Custom widget with WYSIWYG
- Limit number of widgets in widget area
- How to create pagination for homepage with widgetized area?
- Hooking action once but called twice
- How to update the widget form when the image is selected?
- How can I add an author-box below a post?
- Override WordPress Widget CSS Classes?
- Help me out with this Undefined index ?
- displaying tags in a widget
- Dynamic Sidebar and XHTML Validity?
- Displaying a WordPress widget by name
- How to use wordpress content class?
- How to use get_results() in widget front end?
- How to best include widget area just on homepage?
- Remove “Content” and “Discussion” from Right Now Dashboard Widget
- Different widgets in sidebar on sub-children pages?
- Why custom widget won’t appear in Block editor (Gutenberg)?
- Can the qTranslateX-Plugin translate non-article text? [closed]
- Custom widget is not appearing in the admin area
- A/B test options at the widget level [closed]
- Random sidebar/widget background
- Display custom widget value in header.php
- Creating a widget that displays the content of a page
- How to place my g+ or fb plugin at the bottom of post or page?
- WP 3.3 RC1 new switch_theme() method foobars sidebars
- How to Catch Last Widget box From Same Widget Area?
- Countdown Widget
- recent comments filter by author, page, category
- How do I get my custom widget to show on live site?
- How can I add a widget area to the top of the Dashboard?
- How to prevent Widget from echoing to wrong position in DOM
- Search box displaying just title → Default WordPress Widget for Search Box
- Need two sidebar (right and left)in Twenty Seven theme
- Fatal Error (Call to a member function… ) on production site, but not development site
- conditional widget title
- Add Social Media icon widget to customizer
- Create a setting at backend,to print only selected categries at front-end
- Widget Admin page and Javascript enqueuing
- Change Widget that display posts from categories to tags
- Help with custom widget
- Using AJAX in WordPress Widget
- Create a widget to display image and Title?
- How can I get the sidebar id on the current page?
- How add short description Featured Products or Related Products
- call coupon press advanced search widget anywhere in theme?
- Tabbed navigation in widget backend
- How to remove calendar widget?
- twenty twelve theme widgets not working
- How to completely remove the sidebar? [closed]
- Random disappearance of footer widgets [closed]
- How to add an image as a bullet point in a specific WordPress widget? [closed]