Skip to content

Instantly share code, notes, and snippets.

@usainicola
Created December 13, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usainicola/d41d27c6d3b9e927f588a548e067819e to your computer and use it in GitHub Desktop.
Save usainicola/d41d27c6d3b9e927f588a548e067819e to your computer and use it in GitHub Desktop.
wp ajax get template part
<?php
function ajax_get_template_part() {
check_ajax_referer('ajax_get_template_part','nonce');
$part = esc_attr($_POST['template_part']);
if (!$part) {return;}
get_template_part($part);
die();
}
add_action( 'wp_ajax_nopriv_ajax_get_template_part', 'ajax_get_template_part' );
add_action( 'wp_ajax_ajax_get_template_part', 'ajax_get_template_part' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment