1

I have the following really simple code:

function load_peoplesoft_results() {
    global $wpdb;
    echo "<h2>Results</h2>";
}
add_shortcode('load_peoplesoft_result_page', 'load_peoplesoft_results()');

And I put the following on the page I want to display the page:

[load_peoplesoft_result_page] 

But when I load the page, it just displays the above. I checked the error log, and got the following:

[22-Jul-2019 10:26:49] PHP Notice:  do_shortcode_tag was called <strong>incorrectly</strong>. 
Attempting to parse a shortcode without a valid callback:
load_peoplesoft_result_page Please see 
<a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> 
for more information. (This message was added in version 4.3.0.) 
in \wp-includes\functions.php on line 4231

I also tried putting it in a plugin in a different site where I have some shortcodes implemented that are working fine, but had the same issue. No idea what is going on.

Any advice or ideas are greatly appreciated. Thanks in advance.

2 Answers 2

0

Your shortcode callback function is incorrect:

add_shortcode('load_peoplesoft_result_page', 'load_peoplesoft_results()');

You've included the (), but only the function name should be passed:

add_shortcode( 'load_peoplesoft_result_page', 'load_peoplesoft_results' );

Note that the second argument of add_shortcode() is a "callable". This is a standard PHP feature, and you can read documentation for them here.

2
  • Ok, I'm an idiot. Didn't realize that was there. Thanks for the help. Jul 22, 2019 at 14:58
  • I was facing the same problem, because of typo in function and call back name Jun 18, 2022 at 11:07
1

While using the add_shortcode() inside Plugin, So please use as bellow script to explicitly understandable by Plugin, otherwise the Plugin Can't even know about the Shortcode that you are using.

The magic part is to use callback function with array() and $this variable to introduce the shortcode for Plugin.

add_shortcode('geo_date_converter', array($this, 'geo_date_converter_shortcode'));

Follow bellow script:

class EbDateConverter{

       public function __construct(){

           add_shortcode('geo_date_converter', array($this, 'geo_date_converter_shortcode'));
        
       } 


        public function geo_date_converter_shortcode() {

            ob_start();

            $this->call_dateConverter();

            return ob_get_clean();

        }

        public function call_dateConverter() {

          echo 'Shortcode is Working';

        } 

     }
     
     $EbDateConverter = new EbDateConverter();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.