我想使用外部HTML作为我的Wordpress网站的某些页面的内容。
即,目前我将html直接放入wordpress中的页面。但是,我不喜欢这样,因为我喜欢使用具有语法高亮,搜索/替换等功能的编辑器。 我想知道是否有一种方法可以通过functions.php文件调用外部HTML文件中的内容来插入页面内容。
(我不想使用javascript / jquery。我已经有效地工作了,但我想知道是否有通过php的方法。)
按照两个链接的指示(@zipkundan,@ pierre),这是我放在一起的最终代码,就像一个魅力:
// 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;
}