Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Are widgets meant to be used outside of sidebars?

My case: I have this html block which I want to use every time I display a post with category of "Story". I was going to make a widget to reduce duplicate code. Is there a better way to apply this html block to every displaying of a "Story" post?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

If the category is Story, then make a template file, and name it as category-story.php (make sure the slug is 'story'). Put your code in this file. WordPress will automatically display the posts from Story category using this template. (More about category templates here). And yes, you can use widgets outside of the sidebar, read how.

share|improve this answer

I frequently use widgets outside sidebars. It's a fantastic way to make editing content in WordPress easier, however in your situation you may wish to use a file named 'category-story.php' or use the is_category() conditional tag to display content when a given category is viewed.

share|improve this answer

Widgets are just placeholders with enhanced functionality. I build a plugin once to add widgets to the head and footer sections of an HTML document.
I’d say it depends on your needs: If you need some configuration use a widget. Otherwise shortcodes or special templates may do the same job.

share|improve this answer

Yes, one common use is the Widgetized Footer. The typical ones enable one to put three or four columns in the footer which you populate via widgets.

share|improve this answer

Your Answer

 
discard

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.