Showing custom content from specific function in a page
I have a custom php function that returns some text that I would like to show in a specific wordpress page
The fastest idea that comes to my mind, is to return that content through a shortcode and put that shortcode in the given page.
But for the sake of learning better approaches I’ve been thinking that this method, performance-wise, is very poor, so maybe there is a better way to show this content the same way a shortcode do, but straight from code.
Let’s say that the content is shown in the page “My Custom Page” with URL https://example.com/my-custom-page (lets say that the page wp_post id is number 50 in case this helps for query purposes)
Any ideas on how to improve this?
Or shall I stick to the shortcode method?
I’m also thinking on hardcoding in the template the function as page-template (something like page-my-custom-page.php) but still I’m not sure if there is an additional more efficient way, that is theme agnostic.