Social media sharing in posts

hi,

please advise how to add social media sharing buttons in category archive page.

I pasted following code in child version of functions theme:

// Add Social Sharing after the single post content
// =============================================================================

function x_add_social_sharing ( $content ) {
if ( is_singular(‘post’) ) {
echo do_shortcode(’[share title=“Share this Post” facebook=“true” twitter=“true” google_plus=“true” linkedin=“true” pinterest=“true” reddit=“true” email=“true”]’);
}
}
add_action(‘x_before_the_content_end’, ‘x_add_social_sharing’);

This works,but doesnt seem to work on category archive page. Similarly, the plugin i am using doesnt work on your category archive page either although its ticked accordingly.

please advise?

many thanks,

Darryn

Hey Darryn,

Please update the code to:

// Add Social Sharing after the single post content
// =============================================================================

function x_add_social_sharing ( $content ) {
    if ( is_singular('post') || is_category() ) {
        echo do_shortcode('[share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
    }
}

add_action('x_before_the_content_end', 'x_add_social_sharing');

Hope this helps.

Hi Jade,

Thanks so much for the code. It unfortunately still doesn’t show up on Category Archive page.

Please see attached screenshot.

Regards,

Darryn

Hello Darryn,

Thanks for updating the thread. :slight_smile:

Please use the solution shared in following thread:

Thanks.

Thanks Prasant,

Still no luck, I replaced the previous code with the one you sent and nothing.

Please advise what I’m doing wrong?

Darryn

Hey Darryn,

Please update the codes you currently have for the social media sharing to:

// Add Social Sharing after the single post content
// =============================================================================

function x_add_social_sharing ( $content ) {
    if ( is_singular('post') || is_archive() ) {
        echo do_shortcode('[share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
    }
}

add_action('x_before_the_content_end', 'x_add_social_sharing');
add_action('x_before_the_excerpt_end', 'x_add_social_sharing');

If it is still not displaying, please provide us with the admin and FTP access to your site in a Secure Note:

Hello Darryn,

I have logged in and updated the code into this:

function x_add_social_sharing() {
	echo do_shortcode('[x_share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
}
add_action('x_after_view_global__content', 'x_add_social_sharing');

It is still not displaying because of caching since you have installed WP Optimize plugin. Clear all your caches and test the site again.

Please let us know how it goes.

Hi RueNel,

Thank you so much, but still nothing. I have deactivated WP Optimize plugin and cleared cache and still nothing? Just to add, which may or may not help, it also doesn’t work with plugin sassy social media on category archive pages so may be core issue with the theme as it does work with avada,but as mentioned in un-related support message, I would prefer to stick with X Theme and not move back to Avada for this website.

Regards,

Darryn

Hi Darryn,

Above code will work on standard post format on archive page. Now for it work on other post format, please update code this:

function x_add_social_sharing() {
  echo do_shortcode('[x_share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
}
add_action('x_after_view_global__content', 'x_add_social_sharing');
add_action('x_after_view_integrity_content-image', 'x_add_social_sharing');
add_action('x_after_view_integrity_content-quote', 'x_add_social_sharing');
add_action('x_after_view_integrity_content-link', 'x_add_social_sharing');
add_action('x_after_view_integrity_content-video', 'x_add_social_sharing');
add_action('x_after_view_integrity_content-audio', 'x_add_social_sharing');

The location of social media sharing will be different depending on the post format. This is by default available on single post page only. See this screencast on what I mean my difference on location: https://screencast-o-matic.com/watch/cqjVXEOGfS

Now if you intend it to be inside the box of the article not after the post footer, it is another template change. For example, for image type post, copy this file:
\wp-content\themes\x\framework\views\integrity\content-image.php
To the same folder path on your child theme here:
\wp-content\themes\x-child\framework\views\integrity\content-image.php
You might need to create the folder on your child theme. Edit the copied file. Look for this part:

    <?php else : ?>
    <header class="entry-header center-text">
      <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 x_integrity_entry_meta(); ?>
    </header>
    <?php endif; ?>

On that template, you can see there is an if else statement. The first process the display for single post, then on the else part is for archive. On the else part of the code, after this line:

<?php x_integrity_entry_meta(); ?>

Add this:

<?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"]');?>

You need to repeat that process, on all other post type aside from standard. See below on the location difference I describe above:

That is an image post type. Social media sharing inside the black box is added using the last part I discuss. The social media sharing outside the black box is added via function.php, the first part of the code.

Hope this helps.

Thank you Lely,

So much appreciated!!!

Regards,

Darryn

You’re always welcome Darryn.

Cheers!

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