Skip to Content
PHPCODE
Get Template part for ajax
wordpress code / April 14, 2022
// ===================================
// Get Template part for ajax
// ===================================
function jad_return_get_template_part($slug = null, $name = null, array $params = array()) {
$slug=str_replace(“//”,”/”,$slug);
global $wp_query;
do_action(“get_template_part_{$slug}”, $slug, $name);
$templates = array();
if (isset($name))
$templates[] = “{$slug}-{$name}.php”;
$templates[] = “{$slug}.php”;
$_template_file = locate_template($templates, false, false);
if (is_array($wp_query->query_vars)) {
extract($wp_query->query_vars, EXTR_SKIP);
}
extract($params, EXTR_SKIP);
if(!empty($_template_file)){
ob_start();
include($_template_file);
$var=ob_get_contents();
ob_end_clean();
return $var;
}
}
PHPCODE © 2024