Include file in Wordpress

Asked

Viewed 2,887 times

1

I have a site created in wordpress and need to include the command

include 'config.php';

with some specific functions I need to use (including access to an external database).

however, on all pages I include this code gives error.

already tried on theme pages, functions.php, header.php and so far only gives error.

some hint of how to include the above command (or another that does the same function)?

hugs.

1 answer

3


You need to include the full path, even if the file is within the theme. ex.:

// /path/do/wordpress/wp-content/theme/nome-do-tema/config.php
include get_template_directory().'/config.php';

// http://example.com/wp-content/theme/nome-do-tema/config.php
include get_template_directory_uri().'/config.php';

There are several useful functions, as well as system constants for detecting paths and uris within Wordpress.

Here a complete listing of them in the official documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.