简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM