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;
}
Probably this could help you The “the_content” filter