Here, I practically just wrote you a book:
EXPERIENCE EXPERIENCE EXPERIENCE
That's really the best thing.
The best book I've found on it is "The Guitar Grimoire" I forgot the real/full name but theres several of them including a chord one which I never bought but skimmed through. The books are good even if you don't play guitar. I lost the book so I don't know the info, but you'd find it at a music shop easily, all I know is the whole series has the word 'grimoire" in it.
But still, thats just good for learning chords and and scales, which are essential. However, if you really want to broaden your horizons and get good at writing more than guitar music, you'll want to learn several diverse instruments, two of which almost have to be drums and piano. For writing music, piano is the best. Personally I played cello, then guitar, then bass then drums and then got into electronic music, all exactly two years apart with some piano throughout my whole life.
Also, listen to all kinds of music, the AP is good for that too, but professional is obviously better. Don't just stop at rock or whatever it is you like, listen to something you don't like whether it be techno, rap, classical (especially classical) or something crazy like fucking native american music. You can learn something from every genre, as long as the music itself is decent.
Lastly, structure... It may or may not be the hardest thing for you. I found it to be the hardest thing to learn. My advice is to let your music flow and if you can't do it naturally, then stick to a verse/chorus stucture. This is where experience is most important. After a while you'll develope the ability to make good transitions with intros, outros, bridges, interludes, etc.
I'll end this how I started it. Experience... write a shitton of songs daily. Almost every artist has a few long, dry periods where they simply have no inspiration or will to write music. Try to write a song anyways, If you can find out what it is that best inspires you and let it rule your life. If its pain, let your pain be a creative outsource. If its love then think of heartbreak as a good excuse to write music. If you're looking to write lyrics too, then write all the time. Poems, lyrics, essays, short stories, raps, everything even if its not your "style."
Well.. thats how I do it anyway, and if you don't like my music then you probably shouldn't listen to my advice.