Welcome Guest! Login? Checkout

Here’s something I discovered recently, and shows what’s cool about WordPress – it’s so big, that you could discover something that other people will find relatively straightforward.

Previously in WordPress I had been building themes with links to other pages as being static. This has worked out well for a number of years. However recently a mistake occurred when we put the site live with a link back to the staging site.

That isn’t good, so I began to look for alternatives. I had heard of get_permalink(), which gets the permalink of any page or post ID, so I began to think of how the option is saved in the database, and what that option is called.

After a big of digging, I found that 'page_for_posts' is the name of the option, and it’s stored as an ID. Brilliant! This makes life easier, so after a bit of reading, I found that this option is only present when a separate option – 'show_on_front' – is set to “page”, so we need to run a check to make sure that the home page of the blog is a proper page. If not, we simply return the home page using home_url().

Code To Get the Posts Page URL

Simple eh?

This may be simple to some, but it was something I was unaware of until recently. So if you feel intimidated in the WordPress Community, don’t be, as you probably know more than you think!

 
 
 

Comments

Polite Disclaimer: I am welcome, open and willing for corrections to be shared in the comments (with corrections being added to posts and credited), and the comments field should be used to promote discussion and make this post better. I do not know everything and if anybody finds a better way to do something, then by all means please share it below.

However, I'm unable to offer support to posts. The reason being is that WordPress has tens of thousands of plugins and millions of themes. As such, finding out exactly why code doesn't work with your setup is a long process. If you wish for me to look at your code, please use the priority support area.

Comments asking support will be left on the site, but there is no guarantee of answer.

    Comments are closed.