I want to dynamically add a menu item to my site and all I can find on the internet on every single site and YouTube video is to either edit functions.php or download some plugin.
I did find one or two sites that said creating your own plugin is an option, but then they never explain how to hook into the functions.php file.
I have my own plugin and want to add my menu item this way. I cannot for the life of me figure out how to do this. I know it's possible because there are about a dozen plugins that let you paste snippets that somehow inject the code into the functions.php file.
What is this secret that I can't find?
How in the world do I inject code into functions.php from my plugin?

The plugin you need is called Code Snippets.
Or ask ChatGPT to create a plugin starter template file for you.
Plugins are separate from the theme functions.php
You aren’t *injecting* anything into functions.php. Your plugin acts as it’s own functions.php basically (very bad explanation, but gets the point across). You have full access to wordpress hooks, filters, functions/methods, api, etc.
Without seeing your plugin source code, I can not tell you exactly where to do these steps (probably in an init/constructor of your base class) but this should get you started specifically for the admin menu pages.
[https://developer.wordpress.org/plugins/administration-menus/top-level-menus/](https://developer.wordpress.org/plugins/administration-menus/top-level-menus/)
[https://dlxplugins.com/tutorials/plugin-development-how-to-add-custom-menu-items-to-the-wordpress-admin-settings/](https://dlxplugins.com/tutorials/plugin-development-how-to-add-custom-menu-items-to-the-wordpress-admin-settings/)
[https://wordpress.stackexchange.com/questions/67438/how-do-i-make-a-wordpress-plugin-with-menu-item-etc](https://wordpress.stackexchange.com/questions/67438/how-do-i-make-a-wordpress-plugin-with-menu-item-etc)
What you’re trying to do is very bad. Stop.
When you activate a plugin on WordPress it basically *EXTENDS* functions.php. Your plugin shouldn’t alter functions.php at all (in most cases).
Your plugin should contain the code that you are trying to put in functions.php.
Ok, so the good news is there’s virtually no difference between code in functions.php and code in a custom plugin. Basically it boils down to one is a file in the theme folder, the other is a file in a subdirectory of the plugins directory, plus a plugin needs some additional comments at the top of the file.
The other big difference is that WordPress will look for a functions.php file in the current theme folder. But WordPress will also let you manually activate (and deactivate, update, etc.) your plugin in the Sidebar -> Plugins list.
But other than that there’s no difference — the actual code you add to the functions.php or /myplugin/myplugin.php will be executed exactly the same way.
That means there’s no need to inject plugin code into functions.php, you just activate your plugin the usual way it it’ll be there.
Final note: If I understand you correctly and you’re goal is to programmatically add items to your menu then it’s a better idea to make it a plugin. If you put it in functions.php and you or the user changes themes then your code would be lost — not good since you’ll probably always want that item in navigation.
So bottom line, only put code in functions.php if it only affects how the visuals look and behave. If it affects actual site functionality it should go in its own plugin. (Or, as u/AdThat6254 says, you could use a code-snippet plugin if you’re comfortable doing that.)
You don’t inject code into functions.php through a plugin. You instead write the PHP code in a text editor, or something more fancy like VSCode, then paste it by hand into functions.php.
You will have to first set up a child theme in WordPress so that any custom code changes you make will not get overwritten by a future WordPress update.
Through WordPress Admin, navigate to the functions.php file from Appearance > Theme File Editor. You can then hand write code directly into functions.php and save it. Just make sure you DO NOT add the beginning php statement “<?php” in your code because that is already in the functions.php,
If all else fails, an AI code writer like ChatGpt or Claude is excellent for giving you answers to just about any WordPress question.
To create your own plugin you need just one php file that you put in a folder or ZIP.
You need the correct php-comment in / * */ to tell wordpress it is a plugin.
After that you put your php-code If you have a ZIP, you can install it by uploading on the „Install plugins“ page in WordPress. If you have a folder, you can upload this directly to the plugins folder via (s)ftp
You can do nearly the same to create a child theme. For this your php-file has to be called functions.php, you need a style.css with the correct css-comment.
You can add also a screenshot.jpg I usually copy the php/css-comments from the instruction from the developer sites.
Is this helpful?
Others have covered the misguided assumption you’re making; you may learn better how to structure this code by pulling apart a simple open source plugin and seeing how they do it.
You don’t have to extend or inject anything into functions.php. If you’re making a plugin, then you just put the code in your plugin. Forget about functions.php.
Functions.php is only a way to add code to a specific theme. But you’re making a plugin, which is totally separate and independent from a theme. So you don’t need to inject your plugin into your theme, that would be nonsensical. Plugins work regardless of which theme is chosen.