a “require” statement uses a file path, not a URL.
ok, so it would be the FTP path?
It would be a relative path to the location of functions.php.
Hi ragulin,
The quickest way to do an include of that library is thru your theme’s function.php, some suggested steps to do that:
1) Copy the files http://simplehtmldom.sourceforge.net/ inside your theme’s folder eg simplehtmldom
2) Inside your theme’s function.php file, you can use this modified code to include that 3rd party library
function foobar_func( $atts ){
require_once('simplehtmldom/simple_html_dom.php');
$html = file_get_html('http://hokejbal.cz/1-liga/tabulky/');
$ret = $html->find('table.standings', 1);
print $ret;
}
3) You can now call the foobar_func in any of your template files.
The best way to do this is creating a plugin (Google for it) so your custom code won’t be lost when you switch themes.
Okay, my code in functions.php
function foobar_func( $atts ){
require_once('ftp://skkelticz@ftpx.forpsi.com/www/wp-content/themes/sporty-child/simple_html_dom.php');
$html = file_get_html('http://hokejbal.cz/1-liga/tabulky/');
$ret = $html->find('table.standings', 1);
print $ret;
}
add_shortcode( 'foobar', 'foobar_func' );
And errors I get when I try to call the function via shortcode in my page
Warning: require_once(): ftp:// wrapper is disabled in the server configuration by allow_url_include=0 in /web/htdocs2/skkelticz/home/www/wp-content/themes/sporty-child/functions.php on line 11
Warning: require_once(ftp://...@ftpx.forpsi.com/www/wp-content/themes/sporty-child/simple_html_dom.php): failed to open stream: no suitable wrapper could be found in /web/htdocs2/skkelticz/home/www/wp-content/themes/sporty-child/functions.php on line 11
Fatal error: require_once(): Failed opening required 'ftp://...@ftpx.forpsi.com/www/wp-content/themes/sporty-child/simple_html_dom.php' (include_path='.') in /web/htdocs2/skkelticz/home/www/wp-content/themes/sporty-child/functions.php on line 11
-
This reply was modified 8 years, 9 months ago by
Steven Stern (sterndata). Reason: put code in backticks
-
This reply was modified 8 years, 9 months ago by
ragulin.
Most servers (including yours) disable the ability to use URL wrappers (ftp://, http://, etc) in the include() and require() statements.
I’d suggest putting your “simplehtmldom” directory in the WordPress root, where wp-config.php is located. You can then include your file in WordPress with the following line:
require_once(ABSPATH . 'simplehtmldom/simple_html_dom.php');