pages – Add string to gage title if post in category wordpress

Question

Can someone please help me add a string to WP page title depending on category of a post ?

I did this with post title (code below) however I want to extend it to page title.

function recipe_titles ($title,$id=null) {
if (in_category (‘recipes’, $id)) {$title = “Recept: ” .$title; } return$title;

}