link to internal page wordpress

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!!

Answers


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.


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


Need Your Help

Alternative to BerkeleyDB?

berkeley-db dbm

I'm looking for a dbm-like library that I can use in place of Berkeley DB, which I'm currently using. My main reason for switching is the licensing fees for BDB are pretty high (free for open sourc...