I'm trying to think of how to do this but I'm drawing a blank.

I need to create a widget, essentially, that someone can add text and an image to (the widget would basically be an image in one column and text in another). The key is that I would need 4 of these widgets (one for each post category on my site).

My plan was to create an if statement in the template file to only show this html block based on the category/tag name. However, if I want someone to be able to easily edit it then that won't work and I'll really need a widget.

Would I need to create a custom widget area in the template and then register 4 new widgets, then just use php within the them file (if statement) to only show the one for the current category/tag?

FOr reference, the pages in question are at the site.com/tag/baseball level (tag/basketball, tag/football, etc.) so a user viewing the site.com/tag/football page should only see the widget with the image and text for football.

What should be my direction for this?

  • Your question sounded opinion-based, but yes, a widget would allow easy editing of the widget options via the WordPress admin UI. However, you could just create 1 widget and use an option which stores the tag ID or maybe slug, then use an if conditional to display the widget conditionally based on the current tag (in the page URL).
    – Sally CJ
    Feb 25 at 5:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.