wp-lemon Docs

Special pages

Special pages

Special pages is a feature in wp-lemon to make it easier to store and then access crucial pages in your codebase of your website by creating a field in the customizer to select a page as a specific special page. Prior to this feature you could link to pages via the page ID or hardcoding the link in the codebase.

But this method is prone to errors because pages can be renamed or deleted and thus the hardcoded link or page ID would be invalid.

Examples of special pages

But what would you classify as a special page?

As it's in the name, we use this method for pages that are 'special', or crucial for the website. Good examples of pages that are commonly defined as 'special pages' within a website are custom registration pages, crucial forms or landing pages that are cornerstone content for a brand/website.

Creating your own special page

To manage your own special page you'll first need to register it the hooks.php file like so:

/**
* Register special pages entries.
*
* This function is used to add special pages to the theme.
* The special pages are used to store important pages in the theme.
*
* @param array $pages Existing special pages.
* @return array updated array with new registered special pages.
*/
function special_pages($pages): array
{
// add a new special page
$pages['open_application'] = [
'type' => 'page',
'label' => esc_html__('Open application', 'wp-lemon-child'),
];
// add a new special page to an external link
$pages['bank_page'] = [
'type' => 'url',
'label' => esc_html__('Bank page', 'wp-lemon-child'),
];
return $pages;
}
add_filter('wp-lemon/filter/special-pages', __NAMESPACE__ . '\\special_pages');

This creates a sort of "placeholder" for your special page. The key you set can be used to access to special page in the global context but only once you select a page as the special page you desire.

After you've done this you can navigate to the Customizer in WordPress. Under wp-lemon > special pages you'll now find drop down menu's with the default special pages and the ones you've just added.

After you've done this you can navigate to your Customizer in your WordPress. Under special pages you'll now find drop down menu's where you can select your special pages. Using the code example above it will look like this:

afbeelding

Using special pages in your code base

Now you're all set up you can start using it in your website. Special page entries live under the global pages key and a special page entry consists of an array with id, link and title. The most common way to use it is in your twig file. Again elaborating on the examples above you can do this like so:

<a href="{{ pages.open_application.link }}" class="theme-button">
Apply here
</a>

I you want to use it in you controller layer for any reason you can use it like this in you php files:

$pages = WP_Lemon_Site::get_site_information('pages');
$special_page = $pages['my_special_page'];
Edit this page on GitHub