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

I'm trying to make a dynamic button that goes to portfolio page (no matter what ID/name it has), it's currently like this:

$portfolio_page = get_option('theme_portfolio_page');
$portfolio_pid = get_page_by_title($portfolio_page);

     <a href="<?php echo get_option ('theme_portfolio_page') ?>">Voltar</a>

The problem is that it links based on the page name, and when it has space on the name it bugs... So I would need a code that links dynamically to the portfolio page by ID

When I try to change to get_page_by_id


share|improve this question
Whenever in doubt about a WordPress function, check the Codex, get_page_by_title, there you'd have found the correct function EAMann is referencing bellow. And checking the documentation of get_page will solve the doubt you are commenting about... – brasofilo Feb 11 '13 at 21:42

That's because get_page_by_id isn't a function in WordPress.

You want get_page.

share|improve this answer
When I try get_page or get_page_link instead of get_page_by_title it still links trough the title – Lucas B Feb 11 '13 at 21:17

Try using Custom fields.

1.Add the page Id as a custom field value, for example "page_id".

add the following to your template file

$post = get_post_meta( get_the_ID(), 'page_id', true );

Thus you will get the link of the page in $post

Then give this is in your anchor tag as href

<a href="<?php echo $post ?>" > Something</a>

Hope this solves your problem

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.