WordPress.org

Ready to get started?Download WordPress

Forums

How to Add icon to a specific category posts (3 posts)

  1. Anneka
    Member
    Posted 1 year ago #

    Hi, my question is it possible to add a custom image or icon at the beginning of specific category type posts as default?

    for example, all posts under category "story" would automatically have a specific icon assigned at the beginning of its title, like:

    [img] Title of The Story Category 1
    [img] Title of The Story Category 2
    [img] Title of The Story Category 3
    [img] Title of The Story Category 4

  2. PinkishHue
    Member
    Posted 1 year ago #

    This tutorial should help you: http://wpninjas.com/easily-add-text-to-post-title-based-on-category/

    Just change the appended text to an image URL -

    function my_modify_title( $title, $id ) {
       if( in_category( '*your category name*', $id ) ) {
          $title = '<img src="*YOUR IMAGE URL HERE*" alt="" /> ' . $title;
       }
       return $title;
    }

    You can make a little plugin of this so it will work even if you change your theme: http://codex.wordpress.org/Writing_a_Plugin

    There might be a better way but that's the first suggestion I've come across.

    Good luck!

  3. Anneka
    Member
    Posted 1 year ago #

    Thank you for the reply, appreciate it! also ty for the link

Topic Closed

This topic has been closed to new replies.

About this Topic