Regarding a custom loop and output HTML tags

It seems you are confusing actions and filters here. You are using an action. That means if you want to output some html you have to that inside the function. Now your are returning the value, but nothing is done with it.

So in the last line of your function you should have echo $title_yama rather than return $title_yama.

Also, in your code you are accessing a global variable $title_yama, which you are then erasing. That doesn’t seem to make much sense.