Render file with shortcode into a wordpress plugin

I am relatively new to php and wordpress and I would like to know how I can render a php file without the include statement.

For example if I have two files plugin.php and component.php

Read More

plugin.php

<?php
  add-shortcode('myshortcode', 'myshortcode-func');

  function myshortcode-func()
    // magic function that loads
    $result = LOAD('component.php');
    return $result;
  }
?>

component.php

<div>
   <img scr="<?php getimage() ?>" />
</div>

NB
I don’t want to use include because I think it screws the rendering and insert the page in the flow when called.

Thanks for you help !

Related posts

Leave a Reply

2 comments

  1. How to:

    $php = file_get_contents("component.php");
    eval($php);
    

    eval is very dangerous though and shouldn’t be used in production.

    If this is for production, I’d recommend using hooks/filters (see wordpress source code). This lets you execute blocks of code on the fly, but is more constrained.