During activation of the plugin I'm writing, I insert a custom page. I can add post_content using the wp_insert_post command, which seems like a reasonable way to add a limited amount of content.

For example, something simple as part of an array could be:

'post_content'='<h1> Header </h1>'

However, I would like to add a full page of code. Is there a way, such as perhaps linking to a separate file, to insert significant amounts of content? I've tried 'post_content' => '<link rel="import" href="./test.html">' but that doesn't seem to work.

Has anyone found a way to do this other than putting all the code directly into the array?

  • 5
    You could use file_get_contents() on a file in your plugin to get the contents into a variable and use that as the contents. Or you could create a shortcode for this content and make that the content. – Jacob Peattie Feb 2 '18 at 5:24
  • A variable can hold “significant amounts of content” - maybe best show what test.html contains for better context. – David Sword Feb 2 '18 at 6:03
  • Thanks. I'll try that approach. @DavidSword I haven't developed "test.html" fully yet, but I suspect it would fit within a variable. – tim.rohrer Feb 5 '18 at 14:04
  • @JacobPeattie file_get_contents() works quite nicely, thank you. Write it as an answer and I'll accept it. Cheers! – tim.rohrer Feb 5 '18 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.