I need to store the id and secret key of my FB application. I don’t want to write them directly in my template. What do you recommend ?
2 comments
Comments are closed.
I need to store the id and secret key of my FB application. I don’t want to write them directly in my template. What do you recommend ?
Comments are closed.
I recommend you to store it in WordPress options table using function add_option() function as this is site specific data and not post/category specific.
I know this is an older question, but I still feel like it should contain another suggestion so I’ll throw in my 2 cents.
I use the wp-config.php file for such cases where you have a global constant that should be accessible everywhere. This is what WordPress itself does when it needs to store and access such constants as DB_NAME, DB_USER etc. So my recommendation is to add the following to your wp-config.php like:
Then in the code you can access these values by simply using the constants FACEBOOK_ID and FACEBOOK_SECRET_KEY
This organizes them all into one safe location and also avoids calls to the DB rather than using an already defined const variable.
EDIT: I forgot to mention if you’re working on a php page outside of WordPress, you will have to add something like this to your file:
require_once( __DIR__ . '/wp-config.php');
This example assumes the custom file is in the same directory as wp-config.php