워드프레스 관리자 > 외모 > 테마 편집기 > functions.php 파일에 아래 코드를 추가해주세요.
//워드프레스 포스트(글)의 제목을 표시하는 숏코드
function post_title_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
), $atts, 'post_title' );
$post_title = get_the_title( $atts['id'] );
return $post_title;
}
add_shortcode( 'post_title', 'post_title_shortcode' );
포스트 제목 2번째 자리 문자를 별표시 (ex 홍길동 > 홍*동)
//워드프레스 포스트(글)의 제목 2번째 자리 문자를 별표시
function post_title_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
), $atts, 'post_title' );
$post_title = get_the_title( $atts['id'] );
$strlen = mb_strlen( $post_title, 'utf-8' );
if ($strlen > 2) {
$post_title = mb_substr($post_title, 0, 1, 'utf-8') . '*' . mb_substr($post_title, 2, 1, 'utf-8');
} else {
$post_title = $post_title; // No modification for titles with 2 or fewer characters
}
return $post_title;
}
add_shortcode( 'post_title', 'post_title_shortcode' );
포스트(글)의 제목 1번째 자리 제외 나머지 별표시 (ex 홍길동 > 홍**)
//워드프레스 포스트(글)의 제목 1번째 자리 제외 나머지 별표시
function post_title_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
), $atts, 'post_title' );
$post_title = get_the_title( $atts['id'] );
$strlen = mb_strlen( $post_title, 'utf-8' );
if($strlen > 3){
$showlen = 2;
}
else{
$showlen = 1;
}
$post_title = mb_substr( $post_title, 0, $showlen, 'utf-8') . str_repeat('*', $strlen-$showlen);
return $post_title;
}
add_shortcode( 'post_title', 'post_title_shortcode' );