, ,

[ PHP Functions ] 위젯에 php 코드 & 액션코드 쓰기

정보공방 RAD 입니다.

플러그인 추가 없이 위젯에 php코드를 넣거나 액션코드를 넣는 방법을 알려드리겠습니다. 간단하게 functions.php 내에 소스를 추가해서 적용하면 됩니다.
현재 사용중인 테마 혹은 차일드 테마 내에 functions.php 파일을 찾아 아래 내용을 추가합니다.

// Enable shortcodes in widgets
add_filter(‘widget_text’, ‘do_shortcode’);

// Enable PHP in widgets
add_filter(‘widget_text’,’execute_php’,100);
function execute_php($html){
if(strpos($html,”<“.”?php”)!==false){ ob_start(); eval(“?”.”>”.$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}

 

이제 위젯에서 php 혹은 숏코드를 사용해 보세요.
by RAD

0 답글

댓글을 남겨주세요

Want to join the discussion?
Feel free to contribute!

답글 남기기