Move Social Media Share Buttons
-
Hi everyone! I’m hoping someone can please help me with this.
I’m trying to add custom social media share buttons under the “add to cart” button in my product pages. The social buttons are currently showing under our” product description”. This is the code that I am using:
function add_social_share_buttons($content) {
// Get the current page URL
$url = esc_url(get_permalink());
// Get the current page title
$title = urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8'));
// Create an array of social networks and their respective sharing URLs
$social_networks = array(
'Facebook' => 'https://www.facebook.com/sharer/sharer.php?u=' . $url,
'Twitter' => 'https://twitter.com/intent/tweet?url=' . $url . '&text=' . $title,
'LinkedIn' => 'https://www.linkedin.com/shareArticle?url=' . $url . '&title=' . $title,
'Pinterest' => 'https://pinterest.com/pin/create/button/?url=' . $url . '&description=' . $title,
);
// Initialize the share buttons HTML
$share_buttons = '<div class="social-share-buttons">';
// Loop through the social networks and generate the share buttons HTML
foreach ($social_networks as $network => $share_url) {
$share_buttons .= '<a href="' . $share_url . '" target="_blank" rel="noopener">' . $network . '</a>';
}
// Close the share buttons HTML
$share_buttons .= '</div>';
// Append the share buttons HTML to the content
$content .= $share_buttons;
return $content;
}
// Add the social share buttons after the content
add_filter('the_content', 'add_social_share_buttons');Thank you!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Move Social Media Share Buttons’ is closed to new replies.