Fatal error: function call undefined add_action ()

I have a code for twitter updates -

function twitit() { global $wp_query; $thePostName = $wp_query->post->post_name; echo '<div id="twitit"><a href="http://twitter.com/home?status=Currently reading '.$thePostName.' : '.get_permalink($post->ID).'" title="Click to send this page to Twitter!" target="_blank">Share on Twitter</a></div>'; } function widget_twitit($args) { extract($args); echo $before_widget; echo $before_title; echo $after_title; twitit(); echo $after_widget; } function twitit_init() { register_sidebar_widget(__('Twit It'), 'widget_twitit'); } add_action("plugins_loaded", "twitit_init"); //line 30 ?> 

Fatal error: function call undefined add_action () in C: \ xampp \ htdocs \ shizin \ twitter.php on line 30

+3
source share
4 answers

Just add the line require(dirname(__FILE__) . '/wp-load.php'); before other functions. This should solve your problem.

Remember dirname(__FILE__) means specify the root directory of wordpress, something like www.yourdomain.com/wordpress/

+6
source

As the message says, you defined the add_action() function and still try to use it.

Create it first.


I am looking through your previous questions and it looks like you copied the wordpress plugin code. In this case, do not directly call the page, use the wordpress plug-in system.

+4
source

If add_action appears undefined, you are trying to run it outside of your main theme files - basically, it works without any WordPress processing before using your custom functions. This should be in your theme functions.php file or in the plugin, as Colin pointed out.

The line C:\xampp\htdocs\shizin\twitter.php definitely assumes this is in the wrong place.

+1
source

Move your call to add_action() functions.PHP script inside the current active topic (not in the main .php functions).

0
source

All Articles