Original link: https://justyy.com/archives/62681
Sometimes, we want to include PHP or HTML or other external files in WordPress posts or pages, then we can use the following PHP code to add a short code Short Code Function in WordPress:
function include_php_in_wordpress($atts) { extract(shortcode_atts( array( 'src' => '' ), $atts)); if ($src != '') { if (is_file($src)) { return @file_get_contents($src); } else { return ""; } } } add_shortcode('include_php_in_wordpress', 'include_php_in_wordpress_func');
You can add it to the function of your theme’s Theme Child Template template ( child theme ), so that in a WordPress post or page, you can call it to execute or include the specified file (PHP/HTML):
[include_php_in_wordpress src="/path-to-the-php/hello.php"]
If you want to include some PHP files in some posts, like “related posts”, you can manually select those posts, save them in an external PHP or HTML file, and then use the above shortcode function to include it in all related posts. That way, if you want to insert or remove posts from your “Related Posts” list, you don’t need to update those related posts.
English: Add a Short Code Function to include any PHP or HTML file in a WordPress post or page
There are a total of 251 Chinese characters in this article, count it right.
Add Short Code Function to include any PHP or HTML file in your WordPress post or page . ( AMP Mobile Accelerated Version )
The post Add Short Code (Short Code Function) to include any PHP or HTML file in a WordPress post or page first appeared on Little Laizi’s UK Life and Information .
This article is transferred from: https://justyy.com/archives/62681
This site is only for collection, and the copyright belongs to the original author.