get url page template

I have created a page template where I need current page URL

I have tried




but it shows nothing.

Let me know is anything missing in code.


if you're using a page template, then to get current page URL you could try to use this function:



echo get_permalink();

if you want to print the result

If you want to get URL of current custom page template, get_permalink() should work inside that template as long as the global $post is available.

But if you need to get URL of the custom page template from outside of that template, you need some thing like:

 * @param  string  $template  File name. E.g: `page-templates/page-about.php`
function wpse233616_get_page_template_url($template)
  $theme_root = is_child_theme() ? STYLESHEETPATH : TEMPLATEPATH;

  if ( !file_exists($theme_root . '/' . $template) )
    throw new \InvalidArgumentException( sprintf( __('Template %s not found.', 'textdomain'), $template ) );

  $query = new \WP_Query([
    'post_type'      => 'page',
    'meta_key'       => '_wp_page_template',
    'meta_value'     => $template,
    'no_found_rows'  => 1,
    'posts_per_page' => 1

  if ($query->post->ID) {
    return esc_url( get_page_link($query->post) );
  } else {
    return false;

Category: page template Time: 2016-07-30 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.150 (s). 12 q(s)