Problem when using simple sharing php code
-
Hi, I was looking for a lightweight solution to add an exit intent popup on my site. I tried a few code solutions but couldn’t get them to work. Tried your plugin and seemed fine (albeit only on desktop). However, have now noticed it causes a duplication of my social sharing icons that are generated using this PHP in functions.php
function social_sharing_buttons($content) { global $post; if(get_post_type() === 'post'){ // Get current page URL $simplesharingURL = urlencode(get_permalink()); // Get current page title $simplesharingTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8'); // $crunchifyTitle = str_replace( ' ', '%20', get_the_title()); // Get Post Thumbnail for pinterest $simplesharingThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); // Construct sharing URL without using any script $twitterURL = 'https://twitter.com/intent/tweet?text='.$simplesharingTitle.'&url='.$simplesharingURL.'&via=simplesharing'; $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$simplesharingURL; $whatsappURL = 'https://api.whatsapp.com/send?text='.$simplesharingTitle. ' ' .$simplesharingURL; $linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$simplesharingURL.'&title='.$simplesharingTitle; // Based on popular demand added Pinterest too $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$simplesharingURL.'&media='.$simplesharingThumbnail[0].'&description='.$simplesharingTitle; // Add sharing button at the end of page/page content $content .= '<div class="simplesharing-social">'; $content .= '<p><b>SHARE ON</b></p> <a class="simplesharing-link simplesharing-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>'; $content .= '<a class="simplesharing-link simplesharing-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>'; if (wp_is_mobile()) { $content .= '<a class="simplesharing-link simplesharing-whatsapp" href="'.$whatsappURL.'" target="_blank">WhatsApp</a>'; } $content .= '<a class="simplesharing-link simplesharing-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>'; $content .= '<a class="simplesharing-link simplesharing-pinterest" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank">Pin It</a>'; $content .= '</div>'; return $content; }else{ // if not a post then don't include sharing button return $content; } }; add_filter( 'the_content', 'social_sharing_buttons');
The popup is designed to show on all posts. If you scroll to the bottom of one of the posts you will see the sharing buttons shown twice. I’ve tried checking for the id of the popup and I’ve also given it a name and that didn’t work either. Any idea how I can detect the popup so the sharing buttons don’t get added?
The page I need help with: [log in to see the link]
- The topic ‘Problem when using simple sharing php code’ is closed to new replies.