简体   繁体   中英

wordpress include local root php file

I have a child theme functions.php that I am trying to have include a few local domain files , through the use of short codes, that live outside of the Wordpress file structure.

I cant seem to find whats going wrong. Anyone have any pointers?

child theme functions.php

<?php
// localhost path
define('WEB_ROOT', 'http://www.example.com/');

// includes
function filePost() {
    include WEB_ROOT.'/include/file.php';
}
add_shortcode('fileShortCode', 'filePost');
?>

With default PHP settings you can't include files from external sources, which http://example.com is.

To be able to do that, you'd need to change allow-url-include setting. But perhaps the only thing you have to do, is not referring to a URL, but rather to a local path? This you can retrieve by using Wordpress function plugin_dir_path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM