Skip to content
Advertisement

How do i reference another page in in wordpress theme

I am converting a static an html code to wordpress theme, i want to open another page to open when i click on the anchor tag, how do i go about it. Thanks.

JavaScript

Advertisement

Answer

In WordPress, links are permalinks:

Permalinks are the permanent URLs to your individual weblog posts, as well as categories and other lists of weblog postings. Original link: https://wordpress.org/support/article/using-permalinks

When creating a theme, you must display the links that are available in the admin panel: Admin panel -> Appearance -> Menus

The menu consists of locations, location is the place in the template where the user menu is displayed

I created a mini plugin for you that allows you to create custom menus and display them anywhere

Plugin structure:

JavaScript

My example will be complete and working so that you can create any custom menus in WordPress. I will use the handlebars template engine to make things easier.

And so the contents of the unbywyd-custom-menus.php file:

JavaScript

First you call the plugin class and pass your custom menus to register them:

JavaScript

Then you can customize the menus in the admin panel and add them to your locations Admin panel -> Appearance -> Menus | Manage Locations

and now you can display your menu anywhere in the post using a shortcode:

JavaScript

You will also be able to display it programmatically using php:

JavaScript

Link to GutHub with working plugin

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement