Well, I sometimes hear a riff in my head and try to transfer the notes to my guitar. This can take a lot of practising and sometimes make you end up forgetting the riff while trying to play it
And sometimes I just play around, making up some riff until I get something I like and think sounds cool. And then I kind of hear the riff/riffs that follows as I play.
After that I arrange all my riffs for intro, verse, chorus, bridge, solo and what not. Then I listen to all the riffs and try to come up with lead melodies or vocal melodys and lyrics while having the feeling of the song.
For the solo I also listen to the riff and try to hear a solo inside my head. If that dosn't lead anywhere I improvise a few times (sometimes a lot) until I hear something or plays something I like and that feels good.
The style I mostly write is metal, if that helps you or if it matters.
I don't know if this was helpful, but it's how I kind of do it. Every time is different ofcourse and it doesn't always happen in this order. But I think you should always use your feelings. That's the most important thing IMO. Maybe your thinking like "what do he mean "listen to your feelings", is he crazy!?"
But it comes with time and experience of music and the guitar. At least it did for me. Well, I hope you could get something helpful from this post