add_shortcode() | 숏코드 생성

|

요약

add_shortcode('숏코드이름', '콜백함수');

설명

add_action( 'init', 'rdg_shortcode' );
 
function rdg_shortcode() {
    add_shortcode( 'footag', 'rdg_callback_func' );
}

function rdg_callback_func(){
  return "정상작동";
}

일반적으로 권장하는 사용방법입니다.

add_shortcode( 'bartag', 'wpdocs_bartag_func' );
function wpdocs_bartag_func( $atts ) {
    $atts = shortcode_atts( array(
        'foo' => 'no foo',
        'baz' => 'default baz'
    ), $atts, 'bartag' );
 
    return "foo = {$atts['foo']}";
}

add_shortcode( 'baztag', 'wpdocs_baztag_func' );
function wpdocs_baztag_func( $atts, $content = "" ) {
    return "content = $content";
}

[baztag]content[/baztag] 의 경우는 다음과 작성할 수 있습니다.

숏코드 유무 확인

shortcode_exists()

숏코드가 있는지 확인하려면 shortcode_exists() 함수를 사용해보세요.

숏코드 삭제

remove_shortcode(
    string $tag
);

숏코드를 강제로 삭제하는 방법이 있습니다

참조

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

클릭하여 복사