Cách viết shortcode Visua Composer
Fri Aug 15 2025 02:54:11 GMT+0000 (Coordinated Universal Time)
function smo_custom_slider_service_shortcode($atts = []){ $atts = shortcode_atts([ 'list_service' => [], ],$atts); ob_start(); $list_service = vc_param_group_parse_atts($atts['list_service']); if(is_array($list_service) && !empty($list_service)): ?> <div class="smo-list-service-wrapper-container"> <div class="list-service-deskop"> <div class="list-service-row"> <?php foreach ($list_service as $key => $value) { ?> <div> <a class="rst-item-service" href="<?php echo $value['link']; ?>"> <?php echo $value['title']; ?> </a> </div> <?php } ?> </div> </div> <div class="list-service-mobile"> <div class="swiper list_service_slider"> <div class="swiper-wrapper"> <?php foreach ($list_service as $key => $value) { ?> <div class="swiper-slide"> <a class="rst-item-service" href="<?php echo $value['link']; ?>"> <?php echo $value['title']; ?> </a> </div> <?php } ?> </div> </div> </div> </div> <?php endif; return ob_get_clean(); } add_shortcode('smo_custom_slider_service','smo_custom_slider_service_shortcode'); add_action( 'vc_before_init', 'smo_custom_slider_service_map' ); function smo_custom_slider_service_map(){ vc_map( array( "name" => __( "Custom Service"), "base" => "smo_custom_slider_service", "class" => "", "category" => __( "SMO"), "params" => array( array( "type" => "param_group", 'param_name' => 'list_service', "heading" => __( "List Service"), 'params' => array( array( 'type' => 'textfield', 'value' => '', 'heading' => 'Title', 'param_name' => 'title', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'Link', 'param_name' => 'link', ), ), ) ) ) ); } function smo_custom_slider_key_figures_shortcode($atts = []){ $atts = shortcode_atts([ 'list_key_figures' => [], ],$atts); ob_start(); $key_figures = vc_param_group_parse_atts($atts['list_key_figures']); shuffle($key_figures); if(is_array($key_figures) && !empty($key_figures)): ?> <div class="smo-list-key-figures-wrapper-container"> <div class="swiper list_key_figures_slider"> <div class="swiper-wrapper"> <?php foreach ($key_figures as $key => $item) { ?> <div class="swiper-slide"> <div class=" rst-item-key-figures"> <div class="rst-item-key-figures-value counter"> <?php echo $item['value']; ?> </div> <p class="rst-item-key-figures-label"><?php echo $item['label']; ?></p> </div> </div> <?php } ?> </div> </div> </div> <?php endif; return ob_get_clean(); } add_shortcode('smo_custom_slider_key_figures','smo_custom_slider_key_figures_shortcode'); add_action( 'vc_before_init', 'smo_custom_slider_key_figures_map' ); function smo_custom_slider_key_figures_map(){ vc_map( array( "name" => __( "Key Figures"), "base" => "smo_custom_slider_key_figures", "class" => "", "category" => __( "SMO"), "params" => array( array( "type" => "param_group", 'param_name' => 'list_key_figures', "heading" => __( "List Key Figures"), 'params' => array( array( 'type' => 'textfield', 'value' => '', 'heading' => 'Value', 'param_name' => 'value', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'Label', 'param_name' => 'label', ), ), ) ) ) ); } function smo_custom_slider_teams_shortcode($atts = []){ $atts = shortcode_atts([ 'list_teams' => [], ],$atts); ob_start(); $list_teams = vc_param_group_parse_atts($atts['list_teams']); if(is_array($list_teams) && !empty($list_teams)): ?> <div class="smo-list-team-wrapper-container"> <div class="swiper list_teams_slider"> <div class="swiper-wrapper"> <?php foreach ($list_teams as $key => $item) { ?> <div class="swiper-slide rst-item-team"> <div class="rst-team-avatar"> <img src="<?php echo wp_get_attachment_url($item['avatar']) ?>" alt="" /> <div class="rst-team-avatar-description"> <?php echo $item['description']; ?> </div> </div> <div class="rst-team-info"> <h4> <?php if($item['fname']){ ?> <span><?php echo $item['fname']; ?></span> <?php } ?> <?php echo $item['lname']; ?> </h4> <div class="rst-team-info-social"> <?php if($item['email']){ ?> <div class="rst-team-info-email"> <a href="mailto:<?php echo $item['email']; ?>"><span class="rst-team-info-icon"><svg width="25" height="21" viewBox="0 0 25 21" fill="none" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_512_950)"> <path opacity="0.986" fill-rule="evenodd" clip-rule="evenodd" d="M1.87755 1.73525C8.95951 1.7264 16.0415 1.73525 23.1234 1.76181C23.2665 1.7984 23.3976 1.86037 23.5169 1.94771C20.2798 5.47028 17.0339 8.98467 13.7792 12.491C12.9267 13.2346 12.0743 13.2346 11.2218 12.491C7.98412 8.99429 4.7464 5.49753 1.5087 2.00083C1.47488 1.95665 1.48308 1.92124 1.53329 1.8946C1.65705 1.85052 1.7718 1.7974 1.87755 1.73525Z" fill="white"/> <path opacity="0.974" fill-rule="evenodd" clip-rule="evenodd" d="M0.647542 2.79724C0.69928 2.78933 0.74846 2.79814 0.795083 2.8238C3.31215 5.53339 5.82033 8.25106 8.31967 10.9769C5.82033 13.7028 3.31215 16.4204 0.795083 19.13C0.74846 19.1557 0.69928 19.1645 0.647542 19.1566C0.601839 18.9639 0.560852 18.7692 0.524591 18.5723C0.491803 13.5087 0.491803 8.44509 0.524591 3.3815C0.560852 3.18461 0.601839 2.98989 0.647542 2.79724Z" fill="white"/> <path opacity="0.974" fill-rule="evenodd" clip-rule="evenodd" d="M24.2053 2.79736C24.2544 2.79736 24.3036 2.79736 24.3528 2.79736C24.3985 2.99001 24.4395 3.18473 24.4757 3.38163C24.5085 8.44521 24.5085 13.5089 24.4757 18.5724C24.4395 18.7693 24.3985 18.9641 24.3528 19.1567C24.3011 19.1646 24.2519 19.1558 24.2053 19.1301C21.6882 16.4205 19.18 13.7029 16.6807 10.977C19.1899 8.24938 21.6981 5.52279 24.2053 2.79736Z" fill="white"/> <path opacity="0.984" fill-rule="evenodd" clip-rule="evenodd" d="M9.00869 11.827C9.06043 11.8191 9.10961 11.8279 9.15624 11.8536C9.76583 12.5475 10.4052 13.2025 11.0743 13.8188C12.1644 14.4065 13.2136 14.3357 14.2218 13.6064C14.7628 13.0221 15.3038 12.4378 15.8448 11.8536C15.8939 11.8182 15.9431 11.8182 15.9923 11.8536C18.5093 14.5632 21.0175 17.2808 23.5169 20.0067C23.3976 20.0941 23.2665 20.156 23.1234 20.1926C16.0415 20.228 8.95951 20.228 1.87755 20.1926C1.76093 20.1536 1.64618 20.1093 1.53329 20.0598C1.48308 20.0331 1.47488 19.9978 1.5087 19.9536C4.0186 17.2517 6.5186 14.5429 9.00869 11.827Z" fill="white"/> </g> <defs> <clipPath id="clip0_512_950"> <rect width="25" height="20" fill="white" transform="translate(0 0.975586)"/> </clipPath> </defs> </svg></span> <span class="rst-team-info-text"><?php echo $item['email']; ?></span></a> </div> <?php } ?> <?php if($item['phone']){ ?> <div class="rst-team-info-phone"> <a href="tell:<?php echo $item['phone']; ?>"> <span class="rst-team-info-icon"><svg width="25" height="21" viewBox="0 0 25 21" fill="none" xmlns="http://www.w3.org/2000/svg"> <path opacity="0.989" fill-rule="evenodd" clip-rule="evenodd" d="M6.13618 0.983333C6.72752 0.933604 7.20612 1.12328 7.57201 1.55236C8.58955 2.82768 9.47314 4.18251 10.2228 5.61687C10.3446 5.89212 10.4256 6.17663 10.4658 6.47041C10.4487 6.68685 10.3824 6.89007 10.267 7.08009C9.75677 7.5901 9.20453 8.05752 8.61023 8.48234C9.69006 11.2032 11.7076 13.0661 14.6628 14.071C15.0011 13.7258 15.3325 13.3736 15.6568 13.0143C15.9678 12.6444 16.3727 12.4277 16.8718 12.3639C17.5921 12.4923 18.2695 12.7294 18.904 13.0752C20.0589 13.691 21.1781 14.3549 22.2617 15.0668C22.8562 15.5282 22.9813 16.0769 22.6372 16.713C22.0146 17.4755 21.3004 18.1596 20.4945 18.7655C19.6539 19.43 18.7409 19.999 17.7554 20.4726C17.0173 20.494 16.2957 20.3992 15.5906 20.1881C13.8497 19.6718 12.2298 18.9402 10.7308 17.9933C7.20254 15.7501 4.50025 12.8575 2.62392 9.31557C2.16625 8.36398 1.84227 7.37493 1.65197 6.34848C1.62252 6.11814 1.62252 5.88785 1.65197 5.65751C2.62991 3.99854 3.90375 2.55564 5.47349 1.32882C5.68423 1.1914 5.90512 1.07624 6.13618 0.983333Z" fill="white"/> </svg></span> <span class="rst-team-info-text"><?php echo $item['phone']; ?></span></a> </div> <?php } ?> </div> </div> </div> <?php } ?> </div> </div> </div> <?php endif; return ob_get_clean(); } add_shortcode('smo_custom_slider_teams','smo_custom_slider_teams_shortcode'); add_action( 'vc_before_init', 'smo_custom_slider_teams_map' ); function smo_custom_slider_teams_map(){ vc_map( array( "name" => __( "List Teams"), "base" => "smo_custom_slider_teams", "class" => "", "category" => __( "SMO"), "params" => array( array( "type" => "param_group", 'param_name' => 'list_teams', "heading" => __( "List Teams"), 'params' => array( array( 'type' => 'attach_image', 'value' => '', 'heading' => 'Avatar', 'param_name' => 'avatar', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'First Name', 'param_name' => 'fname', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'Last Name', 'param_name' => 'lname', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'Email', 'param_name' => 'email', ), array( 'type' => 'textfield', 'value' => '', 'heading' => 'Phone', 'param_name' => 'phone', ), array( 'type' => 'textarea', 'value' => '', 'heading' => 'Description', 'param_name' => 'description', ), ), ) ) ) ); }
Comments