link to internal page wordpress

50,040

Solution 1

You could use

<a href="<?php echo get_page_link( get_page_by_title( PAGE_NAME )->ID ); ?>">Link Title</a>

Where PAGE_NAME is the page title you have set in the dashboard.

get_page_by_title() returns an object and we use get_page_by_title( PAGE_NAME )->ID to return the page ID of that page. Note that it is more consistent to rely on the page title (which you set yourself) against page ID (which is set by wordpress).

get_page_link() retrieves the permalink of that page ID you passed as parameter.

Solution 2

You can simply link to the page in the HTML body of the home page. For example:

<a href="/index.php/your-page">your page</a>

or

<a href="index.php?page_id=###">your page</a>

Where ###, put the post ID.

More examples

Edit:

If you are editing a template, and wish to obtain the permalink of the post using its ID, use get_permalink($id)

More information about this function

Edit 2:

Based on your comments, you have to switch the permalink format. In WP Admin, find Permalink Settings, and set them to /%postname%/

Read more about these settings here

Share:
50,040
Ben
Author by

Ben

Command About me is undefined, type "man overben" to get more informations about this user

Updated on September 30, 2020

Comments

  • Ben
    Ben over 3 years

    I'm a newbie to wordpress, I added a new page via dashboard, and I want to make a link to this page from the home page so I would love to know what function does that,

    I think it would be something like: >LINK

    Thanks in advance!!

  • Ben
    Ben over 11 years
    yes but I would like to have something like: mysitename/mypage isn't it possible?
  • djdy
    djdy over 11 years
    What is the URL you are getting for the page right now? You probably have to edit permalink format in WP Admin.
  • Ben
    Ben over 11 years
    right now, in my main page (i m in local server) 127.0.0.1/wordpress and I would like to have this url when I click on the link: 127.0.0.1/wordpress/MYPAGENAME
  • Ben
    Ben over 11 years
    I modified my permalink setting as you said and edited my link to echo get_permalink('MYPAGENAME') when I click nothing happens and when I look at the source code, href is empty
  • djdy
    djdy over 11 years
    get_permalink() excepts an ID, not a name. Where are you putting echo get_perma...?
  • Ben
    Ben over 11 years
    i m putting it between my <a> </a tags .. where can I get the ID of my page?
  • djdy
    djdy over 11 years
    Are you doing this in a template file, or are you still in Wordpress admin? If it's the latter, use what I suggested as the very first option in my answer.
  • Ben
    Ben over 11 years
    I m doing it in my template file (my header)
  • djdy
    djdy over 11 years
    You can find the page ID in WP Admin. Click edit on the page you want to obtain the permalink to, and you'll see the ID in the query string in your browser.
  • Ben
    Ben over 11 years
    yes I tried it, but doesn't work either.. :( it links to the links in Dashboard .. I want a link to a page, I thought it would be simple.