skip to Main Content

We would like to add a custom function of a shortcode in wp_include/functions.php.

This is the function:

function url_id() {
 
    $apiUrl = 'https:exampleurl.api.com/exemple123';

    $response = wp_remote_get($apiUrl);

    return wp_remote_retrieve_body($response);

}
add_shortcode('session_id', 'url_id');

But we were getting this error:

There has been a critical error on this website.
Learn more about troubleshooting WordPress.

After reading some more troubleshooting documentation we added these two lines in wp-config:

define( 'WP_DEBUG', true );

define( 'WP_CACHE', true );

And after that we are getting this error:

Fatal error: Uncaught Error: Call to undefined function add_shortcode() in /home/c1624672c/public_html/woo/wp-includes/functions.php:18 Stack trace: #0 /home/c1624672c/public_html/woo/wp-settings.php(111): require() #1 /home/c1624672c/public_html/woo/wp-config.php(104): require_once(‘/home/c1624672c…’) #2 /home/c1624672c/public_html/woo/wp-load.php(50): require_once(‘/home/c1624672c…’) #3 /home/c1624672c/public_html/woo/wp-blog-header.php(13): require_once(‘/home/c1624672c…’) #4 /home/c1624672c/public_html/woo/index.php(17): require(‘/home/c1624672c…’) #5 {main} thrown in /home/c1624672c/public_html/woo/wp-includes/functions.php on line 18

There has been a critical error on this website. Learn more about troubleshooting WordPress.

2

Answers


  1. If you want to add custom shortcodes to your website, that can be done via a custom plugin, or in your theme (as I suspect you’re trying to do).

    Instead of editing wp-includes/functions.php, add your code to wp-content/themes/<name-of-your-theme>/functions.php.


    You should never edit the core files of WordPress, which includes all files in /wp-admin and /wp-includes. When you upgrade WordPress in the future, these files will be overwritten, and you’ll lose any changes you’ve made.

    The error message occurs because you’re attempting to use the add_shortcode() function before WordPress has fully loaded, and defined all available functions.

    Login or Signup to reply.
  2. Please change the shortcode parameter session_id because session_id predefined function in wordpress see the blow or your code

    add_shortcode('session_id', 'url_id');
    

    But right code will be work when you change the session_id.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search