Skip to content

Instantly share code, notes, and snippets.

@sunilw
Created March 13, 2014 23:35
Show Gist options
  • Save sunilw/9539401 to your computer and use it in GitHub Desktop.
Save sunilw/9539401 to your computer and use it in GitHub Desktop.
wordpress ajax handler
<?php
/**
*
* Call functions from here
*
* Note: this file does not override the parent themes functions file.
* Instead, it gets loaded _before_ the parents functions.php gets loaded
*
*/
/*
/* testimonials custom post type
*/
$dirName = dirname(__FILE__);
$baseName = basename(realpath($dirName));
function add_admin_url_to_header() {
$admin_url = '"' . admin_url('admin-ajax.php') . '"' ;
echo '<script>var ajaxurl = ' . $admin_url . '</script>' ;
}
add_action('wp_head','add_admin_url_to_header');
function send_ajax() {
wp_send_json_success(); //give true and die
//echo example
echo "hello from ajax_send";
die();
}
add_action('wp_ajax_send_ajax','send_ajax');
add_action('wp_ajax_nopriv_send_ajax','send_ajax');
include_once("inc/cpt_testimonials.php") ;
function testimonialsUI_styles()
{
wp_enqueue_style( 'testimonialsUI_styles', get_stylesheet_directory_uri().'/stylesheets/testimonialsUI.css' );
}
add_action( 'wp_enqueue_scripts', 'testimonialsUI_styles' );
function load_testimonial_behaviours()
{
wp_enqueue_script(
'testimonials_UI',
get_stylesheet_directory_uri() . '/inc/testimonial-ui-behaviours.js',
array('jquery')
);
}
add_action('wp_enqueue_scripts', 'load_testimonial_behaviours');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment