Title: Adding HTML within widget title
Last modified: August 20, 2016

---

# Adding HTML within widget title

 *  Resolved [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/)
 * Hi there
 * I would really like to put HTML in the widget title box so that I can link the
   title to my taxonomy page. Could someone show me how I can go about doing this?
   I have tried removing strip tags etc with not much success.
 * Many thanks
 * [http://wordpress.org/extend/plugins/flexible-posts-widget/](http://wordpress.org/extend/plugins/flexible-posts-widget/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [DaveE](https://wordpress.org/support/users/dpe415/)
 * (@dpe415)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193507)
 * Hi duncmorley,
 * This would best be done within a custom HTML template. Flexible Posts Widget 
   supports creating your own templates for displaying the posts widget. Instructions
   for getting started with the custom templates are here: [http://wordpress.org/extend/plugins/flexible-posts-widget/installation/](http://wordpress.org/extend/plugins/flexible-posts-widget/installation/).
 * Once you’ve got your own template running, you’ll want to concentrate on editing
   line 13, where the code is: `echo $before_title . $title . $after_title;`. You
   should be able to wrap the title in a link by adding your link HTML around the`
   $title` inside of the before & after variables.
 * Hopefully that helps!
 *  Thread Starter [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193509)
 * Thanks. My issue is that I have 3 instances of the same widget on each page (
   in the footer). Each widget is showing all the posts for a different term. I 
   just wanted to link the title to the term page so can’t hard code in 1 link.
 *  Plugin Author [DaveE](https://wordpress.org/support/users/dpe415/)
 * (@dpe415)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193510)
 * Yes, you’d need to setup the custom HTML template so that it will dynamically
   create the link based on the term chosen by the widget instance. You can get 
   the chosen term in your template by using the variable `$term` in the template(
   it’s already setup by the widget beforehand).
 * This codex doc should help: [http://codex.wordpress.org/Function_Reference/get_term_link](http://codex.wordpress.org/Function_Reference/get_term_link)
 *  Thread Starter [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193518)
 * I really can’t work out how to do this. I’m using
 * `<?php echo get_term_link($term->slug); ?>`
 * with zero success.
 *  Thread Starter [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193519)
 * Is it possible to show an example of how to implement this? Many thanks.
 *  Plugin Author [DaveE](https://wordpress.org/support/users/dpe415/)
 * (@dpe415)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193520)
 * Yup, there’s an example of how to use the term link function right on the Codex
   link I provided before: [http://codex.wordpress.org/Function_Reference/get_term_link#Examples](http://codex.wordpress.org/Function_Reference/get_term_link#Examples).
 *  Thread Starter [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193521)
 * You’ll have to forgive me as taxonomies and terms etc are still a bit confusing
   for me (which is why I’m using your plugin to show them). I have this code but
   it is echoing all 3 terms and not just the one I have selected for the widget.
   I know that is because I’m using a foreach loop. Any chance of showing the correct
   way of doing it?
 *     ```
       <?php $terms = get_terms('tax_services_cat');
       foreach ($terms as $term) {
       	echo '<a href="'.get_term_link($term->slug, 'tax_services_cat').'"><h4 class="widgettitle">'.$term->name.'</h4></a>';
       } ?>
       ```
   
 * Many thanks
 *  Plugin Author [DaveE](https://wordpress.org/support/users/dpe415/)
 * (@dpe415)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193522)
 * Here’s a bit of code that should accomplish what you’re asking for. You’ll need
   to replace lines 12 & 13 of your FPW custom template:
 *     ```
       if ( !empty($title) )
       	echo $before_title . $title . $after_title;
       ```
   
 * with the code from this Pastbin example: [http://pastebin.com/kcRbCn90](http://pastebin.com/kcRbCn90)
 *  Thread Starter [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * (@duncmorley)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193523)
 * That is absolutely wicked, thank you.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Adding HTML within widget title’ is closed to new replies.

 * ![](https://ps.w.org/flexible-posts-widget/assets/icon-256x256.jpg?rev=984592)
 * [Flexible Posts Widget](https://wordpress.org/plugins/flexible-posts-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/flexible-posts-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/flexible-posts-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/flexible-posts-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/flexible-posts-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/flexible-posts-widget/reviews/)

## Tags

 * [link](https://wordpress.org/support/topic-tag/link/)
 * [title](https://wordpress.org/support/topic-tag/title/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 9 replies
 * 2 participants
 * Last reply from: [duncmorley](https://wordpress.org/support/users/duncmorley/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/adding-html-within-widget-title/#post-3193523)
 * Status: resolved