PHP if statement printing the if parameters

This is because the_title() prints the title. You want get_the_title() to ‘get’ the title. Similarly single_post_title prints the title (by default). This can be prevented by using the second argument, e,g,: single_post_title('',false)