Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<?php

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

// No logged in users
bbp_logged_in_redirect();

// 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
add comment

2 Answers

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
add comment

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
WHERE
    p.post_status = 'publish'
    AND
    pm.meta_key = '_wp_page_template'
    AND
    pm.meta_value = 'user-login.php'
LIMIT 1;

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
add comment

Your Answer

 
discard

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.