Adding a badge to new blog post titles

You want to edit the title, and not the content.

Check this for filters you want to use.

If you want to edit your title you should add_filter to it and modify it(the_title). Like so:

add_filter('the_title', 'addBadge2Title');
function addBadge2Title($title)
{
    $seconds = strtotime("now") - strtotime(get_the_date("Y/m/d"));
    $badge = get_stylesheet_directory_uri() . '/library/images/new_ribbon.gif';
    if ($seconds < 10950400) {
        $title="<img class="new_ribbon" width="75"  height="75" src="" . $badge . '" >' . $title;
    }
    return $title;
}

Edit: use badges only for specific categories

If you want to use this code for specific categories you have a few options

  1. First remove add_filter('the_title', 'addBadge2Title'); and keep only the function declaration in functiosn.php and in the archive-{$category-slug}.php file add and remove the filter like so

    if(have_posts()) : while(have_posts()) : the_post()
    
        add_filter('the_title', 'addBadge2Title');
        the_title();
        remove_filter('the_title', 'addBadge2Title');
    
    endwhile; endif;
    
  2. Check if the current post has the category you want the title to be displayed with badges. Modify the function by adding has_category like so:

    function addBadge2Title($title)
    {
        // return the $title unmodified if the post does not have the category
        if(!has_category('badge-category'))
            return $title;
    
        // add the badge
        $seconds = strtotime("now") - strtotime(get_the_date("Y/m/d"));
        $badge = get_stylesheet_directory_uri() . '/library/images/new_ribbon.gif';
        if ($seconds < 10950400) {
            $title="<img class="new_ribbon" width="75"  height="75" src="" . $badge . '" >' . $title;
        }
        return $title;
    }
    

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)