I'm new in wordpress and I don't know two much about this.
Situation There is plugin that generate shortcode [unread_messages]
.
plugin path is wp-content/plugin/chat/
I create a php file under wp-content/custom/messages.php
messages.php
<?php
echo do_shortcode('[unread_messages]');
?>
And I call request through AJAX
like providing url wp-content/custom/messages.php
But this php file gives an error call undefined function do_shortcode
How can I access the value of shortcode through which is not a part of plugin.
You Can't get call AJAX
call like this first you need to register AJAX
call and then send request to admin-ajax.php
Check out this.
add_action('wp_ajax_nopriv_unread_messages', 'unread_messages');
add_action('wp_ajax_unread_messages', 'unread_messages');
function unread_messages(){
$output['response'] = do_shortcode('[unread_messages]');
wp_send_json( $output );
}
After then call AJAX
like this.
jQuery.ajax({
url : 'yourwebsite/wp-admin/admin-ajax.php',
type : 'post',
data : {
action : 'unread_messages'
},
success : function( response ) {
}
});
Learn more about How to Create AJAX in Plugins
Please create a plugin to have an Ajax interface from the default wordpress Ajax.
You can get the source from here:
https://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/shortcodes.php