How to test if the post is in a primary category

You can use this code if you want to add an image in a specific category or a post. You can manipulate this code as you wish:

add_filter( 'the_content', 'add_a_image_in_post' );
function add_a_image_in_post($content){
    global $post;
    if($post->post_type == 'post'){
        //error_log(print_r($post, true), 3, WP_CONTENT_DIR.'/debug.log');
        $all_cats = get_the_category($post);
        foreach($all_cats as $cat){
            if($cat->slug == 'sticky'){
                return $content."<img src=#1 >";
            }
        }
        //error_log(print_r($all_cats, true), 3, WP_CONTENT_DIR.'/debug.log');
        return $content."<img src=#2 >";
    }
    return $content.$content."<img src=#3 >";
}