Title: API key handling
Last modified: June 28, 2024

---

# API key handling

 *  Resolved [lunacer](https://wordpress.org/support/users/lunacer/)
 * (@lunacer)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/api-key-handling/)
 * Hi, I’m trying to import some credentials to the snippet but having trouble.
   
   When I hardcode the credentials inside of base64_encode(), it works fine.However,
   when I save the credentials to the wp_config.php and call it to the file, it 
   responds 401 error.The plugin with the API answered me that the issue is not 
   from their plugin. So I’m wondering, 1. Is it safe to hardcode the API key to
   the snippet?2. If not, what could be the solution for security?
 * Thanks,

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/api-key-handling/#post-17855548)
 * Hi [@lunacer](https://wordpress.org/support/users/lunacer/),
 * You should have no issues loading constants from wp-config in a WPCode Snippet.
 * In wp-config.php you should define those as constants:
 * `define( 'YOUR_API_KEY', 'APIKEYVALUEHERE' );`
 * And then, inside the WPCode snippet you can access those like this:
 * `$your_api_key = defined( 'YOUR_API_KEY' ) ? YOUR_API_KEY : '';`
 * Now you can pass `$your_api_key` to the logic that you have to connect to the
   API.

Viewing 1 replies (of 1 total)

The topic ‘API key handling’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/api-key-handling/#post-17855548)
 * Status: resolved