Social media share buttons on blog

Hello!

I added a code a while back to add these social media share buttons to the end of my blog posts.

I’m wondering if I can add the same buttons right below the title of the blogs.

Ideally I would like it to appear under the title of each of my blogs AND at the bottom of the blog post.

Thank you for your help :slight_smile:
-Nadia

Hi Nadia,

Please login through FTP and go to wp-content/themes/x-child/framework/views/integrity then create _content-post-header.php then add this code to the file:

<?php

// =============================================================================
// VIEWS/INTEGRITY/_CONTENT-POST-HEADER.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================

?>

<header class="entry-header">
  <?php if ( is_single() ) : ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>
  <?php else : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php x_the_alternate_title(); ?></a>
  </h2>
  <?php endif; ?>
  <?php x_integrity_entry_meta(); ?>
</header>

<?php echo do_shortcode('[x_share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]'); ?>

Hope this helps.

I tried logging in through FTP and I don’t understand at all how the program works. I’m afraid I might mess something up.

Is this the only way to do it? Or is there another code that I could possibly add to my functions.php file?

Thank you :slight_smile:

Hello Nadia,

Thanks for updating in!

You may use this code instead:


// =============================================================================
// Add social sharing right below the post title
function add_social_sharing_below_title() {
	echo do_shortcode('[x_share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"] class="mtl"');
}
add_action('x_after_the_content_begin', 'add_social_sharing_below_title');
// =============================================================================

If you want the sharing icons close enough below the titles, then you really have to do it using @Jade’s suggested solution.

Please let us know how it goes.

That code worked perfectly!

The only problem I’m having is the Pintrest button. I tried on different browsers but it’s not working (neither the top nor the bottom)

Is it possible you could check out the Pintrest Link? My website is https://crisisequipped.com

Thank you so much!!!

Hi Nadia,
Thanks again for writing in!
I checked your site and the Pintrest button is working fine.

Please test clearing your cache or in a different PC.

Thanks

Oh ok , I’ll try again.

One last question. What can I do to make it appear only under my blog posts?
I noticed it’s showing up under my header in all my pages except the shop (home, about, contact, etc… every page)

Thank you again!!

Hi Nadia,

I’m a bit confused, I thought it should be added below the title as you already added it a while back at the end of the posts? Would you mind providing more clarification about your question? Or are you referring to the blog index page?

As for home, about, and contact, you should add the shortcode or share element through the builder or editor. The above code is only applicable for posts and pages have different structure. The page content should be changed through editor or builder.

Thanks!

Hello!

Correct, I only want the social icons to appear below the title of my blog posts.

However, if you go to my homepage, contact, about us, etc you will see the following.

What I would like, is for these social icons to be removed from all the pages EXCEPT my blogs .
I hope my question is more clear.

Thank you so much! I really appreciate it :slight_smile:

Hello Nadia,

Please have the code updated and use this instead:

// =============================================================================
// Add social sharing right below the post title
// =============================================================================
function add_social_sharing_below_title() {
  // single post
  if( is_singular('post') ){
    echo do_shortcode('[x_share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"] class="mtl"');
  }
}
add_action('x_after_the_content_begin', 'add_social_sharing_below_title');
// =============================================================================

We would loved to know if this has work for you. Thank you.

Hi!

Yes that works perfect!
You guys are amazing. Thank you for your wonderful support team!
Have a great weekend :slight_smile:

You are most welcome Nadia!
We’re glad we were able to help you out.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.