2017-10-27 1 views
0

functions.php에서 get_template_part()를 사용하여 함수 단축 코드를 개발할 수 있습니까? 템플릿을 렌더링하고 코드를 다시 얻을이functions.php에서 get_template_part 함수를 개발하십시오.

function custom_code($atts){ 
     echo get_template_part('page', 'example'); 
    } 
add_shortcode('custom', 'custom_code'); 

감사

+0

WordPress 개발 관련 질문이있는 사이트가 있습니다. http://wordpress.stackexchange.com – mmm

답변

2

그것은 작은 기능이 가능하며, 같은 뭔가.

add_shortcode('custom', 'fb_template_part_shortcode'); 
function fb_template_part_shortcode() { 

    ob_start(); 
    get_template_part('my_template'); 
    $return = ob_get_contents(); 
    ob_end_clean(); 

    return $return; 
} 
관련 문제