Site icon Hip-Hop Website Design and Development

Redirect users not logged in to the standard login page (and back) from some posts and pages

I’m looking for a hand-coded solution to do the following:

I tested many free plugins but I was really not satisfied: some moves the login form in the protected page, some other lets you put a link to the login page.

I’m quite surprised “vanilla WP” doesn’t offer a login option like the one I’m looking for: you can set a private post, but then it is really private (not to say invisible), then there’s a password solution, but I don’t see many website using this idea, it’s quite uncommon, imho.

Anyway, I would like to know where I can find information about how to code this behaviour myself: there are lots of resources but it looks like anybody has a “snippet” but nothing is “definitive”.