Site icon Hip-Hop Website Design and Development

How do I display PHP file contents on front end of WordPress?

I am working with a third party API for events, the results of the GET request I’ve written are rendered/displayed at this URL (inside the SDK folder):

https://example.com/skiddle-php-sdk-master/demo/result.php

I need to embed these results into specific pages dynamically, so I’ve used a PHP shortcode embed plugin to allow me to echo the file contents onto the page. I have tested this using:

<?php
echo "hello world";
?>

And this displays correctly when using the shortcode. So I have the results of the GET request in the results.php file and the ability to embed PHP directly in the page using a shortcode (rather than creating/editing templates in multiple places).

I am now trying to use: echo file_get_contents or include to render the results.php file onto the page using the following code:

<?php
echo file_get_contents("/skiddle-php-sdk-master/demo/result.php");
?>

But I get a file path warning:

Warning: file_get_contents(/skiddle-php-sdk-master/demo/result.php): failed to open stream: No such file or directory in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(97) : eval()'d code on line 2

I believe this indicates that for some reason the shortcode plugin is expecting the results.php file to be inside the subdirectory of the plugin which it isn’t and shouldn’t be for obvious reasons.

I’ve tried things like this:

/../../skiddle-php-sdk-master/demo/result.php

to no avail. Can anyone help me to understand how I can return the content of results.php using this process?