Tag Archives: The Loop

How to use page attributes inside the loop on WordPress

I like WordPress, but sometimes it works in weird ways.

I recently needed to get information such as the title and some custom fields of the Page I was on. That’s easy, but the Page happened to be ‘News’ which was served from index.php. That apparently isn’t so easy.

To do it, I needed the Page ID. That’s something a lot of people can probably hard-code, but this is a multi-site theme, so no can do. Instead I had to use get_option( ‘page_for_posts’ );.

Here we have it:

<?php $page_id = get_option( ‘page_for_posts’ ); ?> <h1><?php echo get_the_title($page_id) ?></h1>