Created
May 24, 2019 09:16
-
-
Save sudipto-me/476d028bbd329e4c7c1c19a405544e06 to your computer and use it in GitHub Desktop.
Shortcode for the visual composer element.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Shortcode for the visual composer element. | |
*/ | |
/** | |
* Single post two element shortcode | |
* | |
* @param Attributes $atts. | |
* @return string | |
* @since 1.0.0 | |
*/ | |
function fts_single_post_two_shortcode( $atts ) { | |
// Save $atts. | |
$_atts = shortcode_atts( array( | |
'post_image' => '', | |
'post_height' => '', | |
'post_button_text' => esc_attr__('Read More','foreverfitscience'), | |
'post_button_size' => '', | |
'post_button_link' => '', | |
'post_category' => '', | |
'post_title' => '', | |
'title_font_container' => 'tag:h2|text_align:center', | |
'title_use_theme_fonts' => '', | |
'title_google_fonts' => 'font_family:Abril%20Fatface%3Aregular|font_style:400%20regular%3A400%3Anormal', | |
), $atts ); | |
$title = $title_font = $height = ''; | |
$_post_image = !empty($_atts['post_image']) ? $_atts['post_image'] : ''; | |
$_post_height = !empty($_atts['post_height']) ? $_atts['post_height'] : ''; | |
$_post_button_text = !empty($_atts['post_button_text']) ? $_atts['post_button_text'] : ''; | |
$_post_button_size = !empty($_atts['post_button_size']) ? $_atts['post_button_size'] : ''; | |
$_post_button_link = !empty($_atts['post_button_link']) ? $_atts['post_button_link'] : ''; | |
$_post_category = !empty($_atts['post_category']) ? $_atts['post_category'] : ''; | |
$_post_title = !empty($_atts['post_title']) ? $_atts['post_title'] : ''; | |
$_title_font_container = !empty($_atts['title_font_container']) ? $_atts['title_font_container'] : 'tag:h2|text_align:center'; | |
$_title_use_theme_fonts = !empty($_atts['title_use_theme_fonts']) ? $_atts['title_use_theme_fonts'] : ''; | |
$_title_google_fonts = !empty($_atts['title_google_fonts']) ? $_atts['title_google_fonts'] : 'font_family:Abril%20Fatface%3Aregular|font_style:400%20regular%3A400%3Anormal'; | |
$post_image = wp_get_attachment_image_src($_post_image, "large"); | |
$image = $post_image[0]; | |
if(!empty($_post_height)) { | |
$height = ' style="height: '.fts_vc_map_px_checking($_post_height).'"'; | |
} | |
$post_title = $_post_title; | |
$categories = $_post_category; | |
$button_class = !empty($_post_button_size) && ('small' === $_post_button_size) ? 'btn btn-default sm' : 'btn btn-default'; | |
$button_final_array = fts_vc_map_extract_string($_post_button_link); | |
$button_url = (isset($button_final_array['url']) && $button_final_array['url'] != '' ) ? $button_final_array['url'] : '#'; | |
$button_target = (isset($button_final_array['target']) && $button_final_array['target'] != '' ) ? $button_final_array['target'] : ''; | |
if( $_title_use_theme_fonts != 'yes' && (isset($_title_google_fonts) && $_title_google_fonts != '') ){ | |
$google_final_array = fts_vc_map_extract_string($_title_google_fonts); | |
$title_font = fts_vc_map_google_font_style($google_final_array); | |
wp_enqueue_style( 'vcsb_google_fonts_' . $google_final_array['font_family'], '//fonts.googleapis.com/css?family=' . $google_final_array['font_family'] ); | |
} | |
if( !empty($_title_font_container) ) { | |
$title_font_elements = fts_vc_map_extract_string($_title_font_container); | |
$title_tag = $title_font_elements['tag']; | |
$title_font_size = !empty($title_font_elements['font_size']) ? fts_vc_map_px_checking($title_font_elements['font_size']) : '44px'; | |
$title_text_align = !empty($title_font_elements['text_align']) ? $title_font_elements['text_align'] : 'center'; | |
$title_color = !empty($title_font_elements['color']) ? $title_font_elements['color'] : '#ffffff'; | |
$title_line_height = !empty($title_font_elements['line_height']) ? fts_vc_map_px_checking($title_font_elements['line_height']) : '46px'; | |
$title = '<'.$title_tag.' class="post-element-title" style="font-size: '.$title_font_size.'; color: '.$title_color.'; line-height: '.$title_line_height.'; text-align: '.$title_text_align.' !important; '.$title_font.'">'.$post_title.'</'.$title_tag.'>'; | |
} | |
$_return = '<div class="post-element-wrap post-element-overlay"'.$height.'>'; | |
$_return .= '<img class="post-element-img" src="'.$image.'">'; | |
$_return .= '<div class="post-element-content">'; | |
$_return .= '<h4 class="post-element-cat">'.$categories.'</h4>'; | |
$_return .= $title; | |
$_return .= '<a target="'.$button_target.'" href="'.$button_url.'" class="'.$button_class.'">'.$_post_button_text.'</a>'; | |
$_return .= '</div></div>'; | |
// Return the data. | |
return $_return; | |
} | |
add_shortcode('single_post_two','fts_single_post_two_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment