WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I want to add this link: http://localhost/taiwantalk2/user-login/ Which is a Page with a template called page user-login.php:


 * Template Name: bbPress - User Login
 * @package bbPress
 * @subpackage Theme

// No logged in users

// Begin Template
get_header(); ?>

I used to just paste the url of the site (using template_directory) plus the slug (/user-login). The problem is that I have to stick with he same slug (/user-login).

Is there any other alternative?

share|improve this question
up vote 2 down vote accepted

From what I understand, you want a URL to your page, that will work even if you change the page slug?

You can do this by linking to the default permalink for that particular page, for example http://localhost/taiwantalk2/?page_id=139.

This URL will always work even if your permalinks are updated. WordPress handles the redirects for you.

share|improve this answer

I don't quite get what you're trying to achieve. Do you want to create a link to a page that is using your login template?

If that is what you want, you might query the database like that:

SELECT p.ID FROM posts p
LEFT JOIN postmeta pm ON pm.post_id = p.ID
    p.post_status = 'publish'
    pm.meta_key = '_wp_page_template'
    pm.meta_value = 'user-login.php'

using $wpdb. This of course relies on the fact that there's only one page using that template. You can then use the resulting id with get_permalink().

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.