Cresta Social Share Counter Shortcode

Below, you’ll find a detailed guide on how to add the Cresta Social Share Counter Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Cresta Social Share Counter Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Cresta Social Share Counter Plugin and the shortcodes it provides:

Plugin Icon
Cresta Social Share Counter

"Cresta Social Share Counter is a robust WordPress plugin that enables users to display and track the number of shares on various social media platforms."

★★★★☆ (55) Active Installs: 4000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [cresta-social-share]

Cresta Social Share Counter [cresta-social-share] Shortcode

Cresta-Social-Share-Counter shortcode adds social sharing buttons to your content. It checks if the content is singular, then retrieves the selected social buttons from the options. The buttons include Facebook, Twitter, LinkedIn, Pinterest, and Print. Each button is generated with its respective URL, title, and icon. The URL contains the permalink of the post, and the title is shared on the social platform. The Pinterest button has two modes: one for featured image and another for no image. The Print button triggers the print function of the browser. The generated buttons are then returned in a div.

Shortcode: [cresta-social-share]

Examples and Usage

Basic example – The shortcode below will add social share buttons to your content. It doesn’t require any parameters as it will automatically pull the required settings from your plugin configuration.

[cresta-social-share]

PHP Function Code

In case you have difficulties debugging what causing issues with [cresta-social-share] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('cresta-social-share', 'add_social_button_in_content' );

Shortcode PHP function:

function add_social_button_in_content() {
	if ( is_singular() ) {
	$buttons = explode (',',get_option( 'selected_button' ));
	$button_style = get_option('cresta_social_shares_style');
	$cresta_twitter_username = get_option('cresta_social_shares_twitter_username');
	$enable_shadow = get_option('cresta_social_shares_enable_shadow');
	$pinterestMode = get_option('cresta_social_shares_pintmode', 'featimage');
	
	global $wp_query; 
	$post = $wp_query->post;
	
	if($enable_shadow == 1) {
		$crestaShadow = 'crestaShadow';
	} else {
		$crestaShadow = '';
	}
	
	if ( '' != get_the_post_thumbnail( $post->ID ) ) {
		$pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
		$pinImage = esc_url($pinterestimage[0]);
	} else {
		$pinImage = esc_url(plugins_url( '/images/no-image-found.png' , __FILE__ ));
	}
	
	$allButtonsSelected = '';
	$theTwitterUsername = '';
	
	if ($cresta_twitter_username) {
		$theTwitterUsername = '&via=' .esc_attr($cresta_twitter_username);
	}
	
	if(in_array('facebook',$buttons)) {
		$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' facebook-cresta-share" id="facebook-cresta-c"><a rel="nofollow" href="https://www.facebook.com/sharer.php?u='. urlencode(get_permalink( $post->ID )) .'&amp;t='. htmlspecialchars(urlencode(html_entity_decode(the_title_attribute( array( 'echo' => 0, 'post' => $post->ID ) ), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8') .'" title="'.esc_html__('Share on Facebook', 'cresta-social-share-counter').'" onclick="window.open(this.href,\'targetWindow\',\'toolbars=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=320,left=200,top=200\');return false;"><i class="cs c-icon-cresta-facebook"></i></a></div>';
	}

	if(in_array('tweet',$buttons)) {
		$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' twitter-cresta-share" id="twitter-cresta-c"><a rel="nofollow" href="https://twitter.com/intent/tweet?text='. htmlspecialchars(urlencode(html_entity_decode(the_title_attribute( array( 'echo' => 0, 'post' => $post->ID ) ), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8') .'&amp;url='. urlencode(get_permalink( $post->ID )) .''. $theTwitterUsername .'" title="'.esc_html__('Share on Twitter', 'cresta-social-share-counter').'" onclick="window.open(this.href,\'targetWindow\',\'toolbars=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=320,left=200,top=200\');return false;"><i class="cs c-icon-cresta-twitter"></i></a></div>';
	}

	if(in_array('linkedin',$buttons)) {
		$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' linkedin-cresta-share" id="linkedin-cresta-c"><a rel="nofollow" href="https://www.linkedin.com/shareArticle?mini=true&amp;url='. urlencode(get_permalink( $post->ID )) .'&amp;title='. htmlspecialchars(urlencode(html_entity_decode(the_title_attribute( array( 'echo' => 0, 'post' => $post->ID ) ), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8') .'&amp;source='. esc_url( home_url( '/' )) .'" title="Share to LinkedIn" onclick="window.open(this.href,\'targetWindow\',\'toolbars=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=320,left=200,top=200\');return false;"><i class="cs c-icon-cresta-linkedin"></i></a></div>';
	}

	if(in_array('pinterest',$buttons)) {
		if ($pinterestMode == 'featimage') {
			$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' pinterest-cresta-share" id="pinterest-cresta-c"><a rel="nofollow" href="https://pinterest.com/pin/create/bookmarklet/?url='.urlencode(get_permalink( $post->ID )) .'&amp;media='. $pinImage .'&amp;description='. htmlspecialchars(urlencode(html_entity_decode(the_title_attribute( array( 'echo' => 0, 'post' => $post->ID ) ), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8').'" title="'.esc_html__('Share on Pinterest', 'cresta-social-share-counter').'" onclick="window.open(this.href,\'targetWindow\',\'toolbars=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=320,left=200,top=200\');return false;"><i class="cs c-icon-cresta-pinterest"></i></a></div>';
		} else {
			$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' pinterest-cresta-share" id="pinterest-cresta-c"><a rel="nofollow" href="javascript:void((function()%7Bvar%20e=document.createElement(&apos;script&apos;);e.setAttribute(&apos;type&apos;,&apos;text/javascript&apos;);e.setAttribute(&apos;charset&apos;,&apos;UTF-8&apos;);e.setAttribute(&apos;src&apos;,&apos;https://assets.pinterest.com/js/pinmarklet.js?r=&apos;+Math.random()*99999999);document.body.appendChild(e)%7D)());" title="'.esc_html__('Share on Pinterest', 'cresta-social-share-counter').'"><i class="cs c-icon-cresta-pinterest"></i></a></div>';
		}
	}
	
	if(in_array('print',$buttons)) {
		$allButtonsSelected .= '<div class="sbutton '. esc_attr($crestaShadow) .' print-cresta-share" id="print-cresta-c"><a rel="nofollow" href="#" title="'.esc_html__('Print this page', 'cresta-social-share-counter').'" onclick="window.print();"><i class="cs c-icon-cresta-print"></i></a></div>';
	}
	
	return '<!--www.crestaproject.com Social Button in Content Start--><div id="crestashareiconincontent" class="cresta-share-icon '. esc_attr($button_style) .'">'. $allButtonsSelected .'<div style="clear: both;"></div></div><div style="clear: both;"></div><!--www.crestaproject.com Social Button in Content End-->';
	}
}

Code file location:

cresta-social-share-counter/cresta-social-share-counter/cresta-social-share-counter.php

Conclusion

Now that you’ve learned how to embed the Cresta Social Share Counter Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *