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.
<li><a href="about-us.html" class="navlink">About Us</a></li>
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.
<li><a href="about-us.html" class="navlink">About Us</a></li>
2
Answers
You could just put in the static URL
https://www.website.com/about
but that will change if you move the about page into another folder. To keep this dynamic, you can use the wordpress function get_page_link() (if you have the page id) or get_permalink and get_page_by_path if you have the slug. The about page will need to be created in the database first so you can get these parameters.Using page ID: (ex: page ID is 40)
Using slug: (ex: slug is ‘about-us’)
You can also get it using the page title, though this might change over time so I don’t recommend it:
More information about retrieving links dynamically here: https://code.tutsplus.com/tutorials/why-you-shouldnt-code-urls-in-wordpress-themes-or-plugins–cms-23262
In WordPress, links are 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:
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:
First you call the plugin class and pass your custom menus to register them:
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:
You will also be able to display it programmatically using php:
Link to GutHub with working plugin