0 %

Get Permalink By Page Name Or Slug

Get Permalink By Page Name Or Slug

We used to write custom functions to return these values until we discovered you can pass get_permalink a function that will return the ID.

Examples..

Get Permalink By Page Name

<a href="<?php echo get_permalink( get_page_by_path( 'Events' ) ) ?>">Events</a>

Get Permalink By Page Slug

<a href="<?php echo get_permalink( get_page_by_path( 'events' ) ) ?>">Events</a>

Note On Hierarchical Pages and The Slug If you have a page hierarchy you will have to pass the full slug including the parent to the get_page_by_path function.

Example… To get the permalink using method with child page, you need to pass the full slug. In this case we have a child page called “Parties” with a parent page called “Events”.

<a href="<?php echo get_permalink( get_page_by_path( 'events/parties' ) ) ?>">Parties</a>
Việt Lâm Coder

Việt Lâm Coder

Senior Fullstack & System Architect

Cần hỗ trợ website? Gọi / Zalo 0944.71.4545.

Trao đổi về dự án của bạn!

VietLamCoder CMS — Nền Tảng Quản Trị Flat-File Siêu Tốc LamWeb.com.vn — Hệ Sinh Thái Thiết Kế Web & Kho Giao Diện 2026