NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Web Hosting Canada

Last modified : Sep 04 2022

Estimated reading time : 1 minute, 35 seconds - 163 words

This tutorial will show you how to create a custom link for your template page: get_page_link.

First thing we need to do is create our template page in the root folder of our WordPress theme.

Create a template page: For example: User Favorites

 * Recent User Favorites
 * This file contains the markup for recent entries displayed in the
 * 404 pages of the Prime theme.
 * @package Nomdutheme

The next step is creating the new page in WordPress Admin and associate it to the newly created template.

We will use a query, Post type, to match with our template page with the _wp_page_template meta Key and our template name as a value (Remplace user-profile.php by your template page). We will ask to return your page on demand.

function viadirectory_userprofile_id() {
	$args = [
	'post_type'     => 'page',
	'fields'        => 'ids',
	'nopaging'      => true,
	'meta_key'      => '_wp_page_template',
	'meta_value'    => 'user-profile.php'
	$pages = get_posts( $args );
	foreach ( $pages as $page ) 
	return $page;

We will now create our custom permalink in order to load up the desired template. You can also add a custom CSS styling.

We will be using the get_page_link function and include another function, viadirectory_userprofile_id(), which returns the page query.

 	<li style="list-style-type: none;">
 	<li class="<?php if (is_page_template('user-profile.php')) { echo 'active'; } else {}; ?>"></l>

You now have a dynamic link that loads the desired Template Page.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>