Include file in WordPress

1

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

include 'config.php';

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

However, on every page that I include this code gives error.

I have already tried the theme pages, functions.php, header.php and so far only gives error.

Any tips on how to include the above command (or another one that does the same function)?

Hugs.

    
asked by anonymous 24.11.2016 / 22:40

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 to determine paths and uris within WordPress.

Here a complete listing of them in the official documentation

    
25.11.2016 / 03:14