Optimization of a custom loss function
You don't need to change the way optimizer works. You just need to define your loss function in some standard way. 

Checkout the answer in this post to have an idea on an example of customizing loss function in Keras. 

https://stackoverflow.com/questions/45961428/make-a-custom-loss-function-in-keras