functions/social: fork the code from crunchify

As we are customizing it, let's change the function name, but credit the original post and function with a comment.
This commit is contained in:
Kazhnuz 2018-10-25 11:16:16 +02:00
parent c3ede2a4bd
commit 8bd1cc2fb4
1 changed files with 17 additions and 13 deletions

View File

@ -51,32 +51,36 @@ add_action( 'init', 'wpqdouze_post_supports' );
/* 4. Social Network */ /* 4. Social Network */
function crunchify_social_sharing_buttons($content) { function mypost_social_sharing_buttons($content) {
// Fork of mypost_social_sharing_buttons
// You can find the original at the following url:
// https://mypost_.com/how-to-create-social-sharing-button-without-any-plugin-and-script-loading-wordpress-speed-optimization-goal/
global $post; global $post;
if(is_singular() || is_home()){ if(is_singular() || is_home()){
// Get current page URL // Get current page URL
$crunchifyURL = urlencode(get_permalink()); $mypost_URL = urlencode(get_permalink());
// Get current page title // Get current page title
$crunchifyTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8'); $mypost_Title = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');
// $crunchifyTitle = str_replace( ' ', '%20', get_the_title()); // $mypost_Title = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest // Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); $mypost_Thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script // Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify'; $twitterURL = 'https://twitter.com/intent/tweet?text='.$mypost_Title.'&url='.$mypost_URL.'&via=mypost_';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL; $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$mypost_URL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle; $bufferURL = 'https://bufferapp.com/add?url='.$mypost_URL.'&text='.$mypost_Title;
$whatsappURL = 'whatsapp://send?text='.$crunchifyTitle . ' ' . $crunchifyURL; $whatsappURL = 'whatsapp://send?text='.$mypost_Title . ' ' . $mypost_URL;
$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$crunchifyURL.'&title='.$crunchifyTitle; $linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$mypost_URL.'&title='.$mypost_Title;
// Based on popular demand added Pinterest too // Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle; $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$mypost_URL.'&media='.$mypost_Thumbnail[0].'&description='.$mypost_Title;
// Add sharing button at the end of page/page content // Add sharing button at the end of page/page content
$content .= '<!-- Crunchify.com social sharing. Get your copy here: http://crunchify.me/1VIxAsz -->'; $content .= '<!-- mypost_.com social sharing. Get your copy here: http://mypost_.me/1VIxAsz -->';
$content .= '<div class="reagir share-buttons">'; $content .= '<div class="reagir share-buttons">';
$content .= '<a class="btn btn-twitter" href="'. $twitterURL .'" target="_blank"><i alt="twitter" class="fa fa-fw fa-twitter"></i></a>'; $content .= '<a class="btn btn-twitter" href="'. $twitterURL .'" target="_blank"><i alt="twitter" class="fa fa-fw fa-twitter"></i></a>';
$content .= '<a class="btn btn-facebook" href="'.$facebookURL.'" target="_blank"><i alt="facebook" class="fa fa-fw fa-facebook"></i></a>'; $content .= '<a class="btn btn-facebook" href="'.$facebookURL.'" target="_blank"><i alt="facebook" class="fa fa-fw fa-facebook"></i></a>';
@ -92,4 +96,4 @@ function crunchify_social_sharing_buttons($content) {
return $content; return $content;
} }
}; };
add_filter( 'the_content', 'crunchify_social_sharing_buttons'); add_filter( 'the_content', 'mypost_social_sharing_buttons');