When I got my dog Goodboy, he was very sick and needed pills everyday. We tried putting the medication in his food and on his food, and covered in raw hamburger or peanut butter, but upon getting the pill he would spit it out.
So I made taking pills fun. I would gently grasp his lower jar from both sides, toward the back of his jaw, and press gently on both sides and say "Open wide for mama."
After a few times of refusing he learned if he opened his mouth and a pill was popped in, and then I would release his jaw. Holding his mouth shut with one hand and stroking his neck with the other hand, he learned that swallowing pills was not such a bad thing to do. And he got a good treat for doing it.
From then on all I needed to do was touch his lower jar and say "Open wide for mama," and he would open his mouth and I popped the pill in at the back of his throat and with mouth held closed and neck stroked he would swallow the pill.
It was very humorous sometimes when he wanted a special treat he would come and sit at my feet and look at me and open his mouth wide, then close it and whine. He would get his treat. lol