חיפוש ]

יצירת Shortcode פשוט עם Attributes בוורדפרס

יצירת shortcode ניתן לשימוש חוזר עם attributes. זהו הדפוס הבסיסי לכל shortcode מותאם בוורדפרס. לעוד על הוקים בוורדפרס.

function savvy_button_shortcode( $atts ) {
    $atts = shortcode_atts( array(
        'url'   => '#',
        'text'  => 'Click Here',
        'color' => 'blue',
    ), $atts, 'savvy_button' );

    return sprintf(
        '<a href="%s" class="savvy-btn savvy-btn-%s">%s</a>',
        esc_url( $atts['url'] ),
        esc_attr( $atts['color'] ),
        esc_html( $atts['text'] )
    );
}

add_shortcode( 'savvy_button', 'savvy_button_shortcode' );

הוסיפו ל-functions.php. שימוש: [savvy_button url="/contact/" text="Contact Us" color="gold"].

דיון ותגובות
0 תגובות  ]

השאירו תגובה

הוסיפו קוד באמצעות הכפתורים מטה. למשל, בכדי להוסיף PHP לחצו על הכפתור PHP והוסיפו את הקוד בתוך השורטקוד. מצאתם שגיאה בפוסט? עדכנו אותנו...

Savvy WordPress Development official logo