link to internal page wordpress
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.
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
Ben
Command About me is undefined, type "man overben" to get more informations about this user
Updated on September 30, 2020Comments
-
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 over 11 yearsyes but I would like to have something like: mysitename/mypage isn't it possible?
-
djdy over 11 yearsWhat is the URL you are getting for the page right now? You probably have to edit permalink format in WP Admin.
-
Ben over 11 yearsright 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 over 11 yearsI 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 over 11 yearsget_permalink() excepts an ID, not a name. Where are you putting echo get_perma...?
-
Ben over 11 yearsi m putting it between my <a> </a tags .. where can I get the ID of my page?
-
djdy over 11 yearsAre 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 over 11 yearsI m doing it in my template file (my header)
-
djdy over 11 yearsYou 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 over 11 yearsyes 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.