I’ve been reading documents, viewing videos, etc. on how to create a WordPress plugin. I’ve learned how to filter a post, add txt to a post, use conditionals to see if the page is a single post as not to display text throughout the entire site, etc.
The part that I’m not understanding is how to create a plugin, with it’s own menu item that will bring the user to this plugin that im creating.
Lets say for example my plugin should be a blank page (with WordPress header, footer, etc.) that simply displays ‘Hello World!’ – How do I create this very simple plugin, on its own page (not seen all over the site) with its own menu button that brings the user to this plugin?
Do I create a template and a menu item that links to the template? I’m so confused…
I found how to ‘Create page’ in the admin section, but that seems to only create a menu item that corresponds to a blank page where I can add html.
I can’t seem to even find any plugin examples where this is done, but I would think it would be relatively easy to create a plugin that has a menu item so visitors know how to get to the plugin.
If I wanted to create a simple plugin so visitors to my WordPress can click a menu item called ‘Bicycle races’ and be brought to my plugin page where they can view the output of my plugin, a list of bicycle races in this case, how would I accomplish this? Do I create a simple plugin, or do I create a template as well?
Please help me locate any possible plugin examples where this is accomplished.
Thanks
If you want a frontend page you’ll have to create one with your plugin’s shortcode as the content. Then you display your plugin’s output in-place of that shortcode:
you’ll need some plugin options at the very least to allow users to decide how/where your plugin page is accessed. some users may be using
wp_list_pages
to output a menu, others may use awp_nav_menu
instance to enable navigation, and in that case they could have multiple menus registered, and then there’s the matter of where within a menu they’d want it. this answer contains code for auto-adding a menu item to a nav menu, but it may be better to just provide instructions for user’s to add your plugin menu item.as for the “page” itself, there are a few different strategies I’ve seen in various plugins:
the_content
on that page to insert your plugin’s output.