{"id":16606829,"date":"2023-03-29T15:44:56","date_gmt":"2023-03-29T15:44:56","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/problem-when-using-simple-sharing-php-code\/"},"modified":"2023-03-29T15:44:56","modified_gmt":"2023-03-29T15:44:56","slug":"problem-when-using-simple-sharing-php-code","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/problem-when-using-simple-sharing-php-code\/","title":{"rendered":"Problem when using simple sharing php code"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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&#8217;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<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function&nbsp;social_sharing_buttons($content)&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$post;&nbsp;&nbsp;&nbsp;\n\n&nbsp;&nbsp;&nbsp;&nbsp;if(get_post_type()&nbsp;===&nbsp;'post'){\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Get&nbsp;current&nbsp;page&nbsp;URL&nbsp;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$simplesharingURL&nbsp;=&nbsp;urlencode(get_permalink());\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Get&nbsp;current&nbsp;page&nbsp;title\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$simplesharingTitle&nbsp;=&nbsp;htmlspecialchars(urlencode(html_entity_decode(get_the_title(),&nbsp;ENT_COMPAT,&nbsp;'UTF-8')),&nbsp;ENT_COMPAT,&nbsp;'UTF-8');\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;$crunchifyTitle&nbsp;=&nbsp;str_replace(&nbsp;'&nbsp;',&nbsp;'%20',&nbsp;get_the_title());\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Get&nbsp;Post&nbsp;Thumbnail&nbsp;for&nbsp;pinterest\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$simplesharingThumbnail&nbsp;=&nbsp;wp_get_attachment_image_src(&nbsp;get_post_thumbnail_id(&nbsp;$post-&gt;ID&nbsp;),&nbsp;'full'&nbsp;);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Construct&nbsp;sharing&nbsp;URL&nbsp;without&nbsp;using&nbsp;any&nbsp;script\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$twitterURL&nbsp;=&nbsp;'https:\/\/twitter.com\/intent\/tweet?text='.$simplesharingTitle.'&amp;amp;url='.$simplesharingURL.'&amp;amp;via=simplesharing';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$facebookURL&nbsp;=&nbsp;'https:\/\/www.facebook.com\/sharer\/sharer.php?u='.$simplesharingURL;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$whatsappURL&nbsp;=&nbsp;'https:\/\/api.whatsapp.com\/send?text='.$simplesharingTitle.&nbsp;'&nbsp;'&nbsp;.$simplesharingURL;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$linkedInURL&nbsp;=&nbsp;'https:\/\/www.linkedin.com\/shareArticle?mini=true&amp;url='.$simplesharingURL.'&amp;amp;title='.$simplesharingTitle;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Based&nbsp;on&nbsp;popular&nbsp;demand&nbsp;added&nbsp;Pinterest&nbsp;too\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pinterestURL&nbsp;=&nbsp;'https:\/\/pinterest.com\/pin\/create\/button\/?url='.$simplesharingURL.'&amp;amp;media='.$simplesharingThumbnail&#091;0].'&amp;amp;description='.$simplesharingTitle;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Add&nbsp;sharing&nbsp;button&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;page\/page&nbsp;content\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;div&nbsp;class=\"simplesharing-social\"&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;p&gt;&lt;b&gt;SHARE&nbsp;ON&lt;\/b&gt;&lt;\/p&gt;&nbsp;&lt;a&nbsp;class=\"simplesharing-link&nbsp;simplesharing-twitter\"&nbsp;href=\"'.&nbsp;$twitterURL&nbsp;.'\"&nbsp;target=\"_blank\"&gt;Twitter&lt;\/a&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;a&nbsp;class=\"simplesharing-link&nbsp;simplesharing-facebook\"&nbsp;href=\"'.$facebookURL.'\"&nbsp;target=\"_blank\"&gt;Facebook&lt;\/a&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(wp_is_mobile())&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;a&nbsp;class=\"simplesharing-link&nbsp;simplesharing-whatsapp\"&nbsp;href=\"'.$whatsappURL.'\"&nbsp;target=\"_blank\"&gt;WhatsApp&lt;\/a&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;a&nbsp;class=\"simplesharing-link&nbsp;simplesharing-linkedin\"&nbsp;href=\"'.$linkedInURL.'\"&nbsp;target=\"_blank\"&gt;LinkedIn&lt;\/a&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;a&nbsp;class=\"simplesharing-link&nbsp;simplesharing-pinterest\"&nbsp;href=\"'.$pinterestURL.'\"&nbsp;data-pin-custom=\"true\"&nbsp;target=\"_blank\"&gt;Pin&nbsp;It&lt;\/a&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;'&lt;\/div&gt;';\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$content;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}else{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;if&nbsp;not&nbsp;a&nbsp;post&nbsp;then&nbsp;don't&nbsp;include&nbsp;sharing&nbsp;button\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$content;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n};\n\nadd_filter(&nbsp;'the_content',&nbsp;'social_sharing_buttons');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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&#8217;ve tried checking for the id of the popup and I&#8217;ve also given it a name and that didn&#8217;t work either. Any idea how I can detect the popup so the sharing buttons don&#8217;t get added?<\/p>\n","protected":false},"template":"","class_list":["post-16606829","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16606829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16606829\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16606829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}