What is the right way to add PHP code to a certain part of a page

A plugin is just a file that gets loaded into WordPress, it doesn’t have a location on the page. In fact WordPress doesn’t know which page it is yet when plugins are loaded. It may not even be a frontend page!

So if a plugin is just a place to put code such as hooks and filters, how do you embed code in a page?

There are several methods:

  • blocks
  • shortcodes
  • widgets
  • theme template files

You can register blocks/shortcodes/widgets in a plugin, whereas templates files are theme specific.

I recommend searching the site for how to create and use a shortcode, this will be the easiest option for you at the moment.