티스토리 뷰

wordpress/functions.php

단축코드 만들기 예

보라소년 2015. 8. 13. 15:18
// custom_content_bar
function custom_content_bar($attr, $content = null) {
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(10000, 10000) );
    $return_string = '<div class"code-block text-center overlay m-btm-30" style="background:url(';
    $return_string .= $src[0];
    $return_string .= ') center no-repeat; background-size: cover; padding: 30px;" data-stellar-background-ratio="0.5">';
    $return_string .= '<h3 class="colorWhite">'.$content.'</h3>';
    $return_string .= '</div>';
    return $return_string;
}
// custom_content_bar_url
function custom_content_bar_url($attr, $content = null) {
    extract(shortcode_atts(array(
        "src" => 'http://',
        "color" => '#fff',
    ), $atts);
    $return_string = '<div class"code-block text-center overlay m-btm-30" style="background:url(';
    $return_string .= $src
    $return_string .= ') center no-repeat; background-size: cover; padding: 30px;" data-stellar-background-ratio="0.5">';
    $return_string .= '<h3 style="color:'.$color.';">'.$content.'</h3>';
    $return_string .= '</div>';
    return $rerutn_string;
}

function register_shortcodes() {
    add_shortcode('content_bar', 'custom_content_bar');
    add_shortcode('content_bar_url', 'custom_content_bar_url');
}
add_action('init', 'register_shortcodes');

예 : 단축코드 사용예 1

[content_bar]사이트 방문을 진심으로 환영합니다[/content_bar]


예 : 단축코드 사용예 2

[content_bar_url color="#f00" src="http://image1.png"]사이트 방문을 진심으로 환영합니다[/content_bar_url]


'wordpress > functions.php' 카테고리의 다른 글

관리자 글보기에 썸네일 이미지 노출하기  (0) 2016.08.22
add_images_size  (0) 2015.08.13
로그인 세션 늘리기  (0) 2015.08.13
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31