Quite a few possibilities.
Imo a good ine could be that he fights Shanks alongside BB, or at least comes to help when it seems BB is in danger, they fight and fight... either until Aokiji sees a chance and attacks BB, and BB has to get serious and reveal his secret power or whatever, or they effectively manage to bring Shanks close to the grave and at that point Shanks bring out everything to let the other Red pirates escape and he dies soon after. Also it has to fit somewhat Luffy arriving soon after and symbolically give back the hat or at the very least have a last talk with Shanks before he dies. I guess at this point returning the hat to a dead man wouldn't make that sense, way better to give it to his and Makino son.
Or Aokiji could just be in another place so that his expected betrayal takes place somewhere else (even if this seems his best chance, this or when BB attacks Imu, which actually could and should happen before BB fights Shanks). Anyway yes it is a bit weird to find a place for Aokiji in the battle between Shanks and BB. I guess he could also take Beckman and that would be for sure an interesting fight but maybe Oda should also hype Shyriu a bit before Zoro fights him, what he did with Garp was good but the one who shined the most among the BB pirates for sure was Aokiji. Meh, really I don't know.