1

I would like to use external HTML as the content of some pages of my Wordpress site.

I.e., currently I have the html directly into the page in wordpress. However, I don't like this because I like to use an editor that has syntax highlighting, search/replace etc. I was wondering if there was a way through the functions.php file to call content from an external HTML file to be inserted to the page content.

( I don't want to use javascript/jquery. I already have that working effectively, but I want to know if there is a way through php. )


UPDATE - ANSWER

After following instructions from both links (@zipkundan, @pierre), this was the final code I put together that works like a charm:

// add the filter call which will change the content
add_filter( 'the_content', 'insert_html' );
// the callback function - it gets the variable $content which holds default content
function insert_html($content) {
    // I needed the content filtered by page - only for the 'help' page
    if( is_page( 'help' )) {
        // this line gets the html from the file - stores into myHtml var
        $myHtml = file_get_contents(url_to_file);
        return $myHtml;
    }
    // if the page is not 'help', we need to return the content, otherwise page will be empty
    return $content;
}
Community
  • 1
  • 1
DaveyD
  • 337
  • 1
  • 5
  • 15
  • You can in you template include file by function `include('path/to/file')` – Naumov Apr 03 '16 at 16:32
  • 1
    Possible duplicate of [How do I include an external file in PHP?](http://stackoverflow.com/questions/4191364/how-do-i-include-an-external-file-in-php) – Pierre Apr 03 '16 at 17:07
  • @Pierre, thanks - that is a nice link that shows the php function, but it does not answer the question. I am looking for a way to insert it using the functions.php file. I dont want to make a separate template for this page. I need to know id there is some type of content hook/filter that can allow me to insert this content. (Hence, this is not a duplicate) – DaveyD Apr 03 '16 at 18:45

1 Answers1

1

Probably this could help you The "the_content" filter

zipkundan
  • 1,754
  • 1
  • 12
  • 16
  • this worked perfectly as follows. I added my final code to my question post for clarification. Thanks – DaveyD Apr 04 '16 at 00:39