How to add social media sharing buttons on blog post

Hi there,

I have been looking at the forum and I have seem some similar requests.

I understand I need to copy a code and paste it on but I am not too sure where do I find the funcions on the child theme.

I would like to know how to add social media sharing buttons on blog post and where to find where to copy the code. Also, I would like to know if I have to copy the whole code and paste it.

Thank you.

Pablo

Hi Pablo,

Thank you for reaching out to us. First make sure you’ve child theme installed and activated please see https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57 then to find the functions.php file navigate to Appearance > Editor

You will see here a list of files on the right. Find the file functions.php and click to edit the file.

Once you’re in, copy the entire code below:

function x_add_social_sharing() {
		if ( is_single() ) {
  			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_before_the_content_end', 'x_add_social_sharing');

And paste it inside the functions.php file of your child theme at the very end of the file.

Hope this helps!

Thank you Nabeel,

That was useful I did find the funtions. I copy it where it says overwritte or add your custom functions but it didnt save the changes.

Am I doing it right?

My theme is Child X theme.

Thank you for your prompt response.

Is it better to add a plugin?

// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================

Hi Pablo,

It seems that you are using an incompatible version of X and Cornerstone. Your Cornerstone version is updated while X is still in version 5. This would cause some of the features on your site not to work as expected so kindly make sure to update X as well.

Also, the code provided previously should add the social icons for posts. Kindly make sure you add it after the default contents of the file.

Hope this helps.

Hi Jade,

Thanks for your message.

I have updated the x theme, thank you for that.

Now, when I go to function, I looks like the picture you sent. However, it is still not being updated. First time I tried, I went to funtions and, as indicated in the previous remarks, went down to the very end, it went down over the line 300. I copied it but didnt save it. I have tried again, and now when I go to funtions it doesnt scroll down at all. I wont scroll down to line number 26.

Do you guys know whats going on? I havent managed to add the social buttoms yet.

Thank you for your assisstance guys, this can be a bit frutrating and complicating.

Pablo

Hi @Cobalto210,

Please try changing your code to this,

function x_add_social_sharing() {
		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"]');
		}
}
add_action('x_before_the_content_end', 'x_add_social_sharing');

Thanks!

Hi there,

Still cant change it.

Could you please have a look for me?

I have tried four or five times now and still not working.

This is the message that it comes up when I try to save it:

It hasnt been possible to comunicate with the site to to check for fatal errors,therefore the change of PHP has been reverted. You will have to upload your PHP file by other means, like for example using SFTP

No ha sido posible comunicar con el sitio para comprobar los errores fatales, así que el cambio de PHP se ha revertido. Tendrás que subir el cambio a tu archivo PHP por otros medios, como por ejemplo usando SFTP.

Thanks guys,

Hi @Cobalto210,

Sure, I could check it, would you mind providing your SFTP login credentials in a secure note?

Thanks!

Hi @Cobalto210,

Looks like the file functions.php is not writable or not allowed by your host, just try any code like

//this is comment

And it’s gonna throw the same message. I recommend editing your functions.php through SFTP as suggested in the error message. Or, the much faster and easier, use your hosting file manager to edit that file. It’s not going to work no matter what changes you add in the admin side’s functions.php.

Thanks!

I am sorry,

I did not understand any of that.

What is the SFTP?

I dont have tech knowledge, you have to talk to me in a language I understand.

This is beginning to be really annoying now.

How do I solve this?

Thank you

Hi again,

SFTP (Secure File Transfer Protocol ) is a secure version of File Transfer Protocol (FTP). It is basically a way to connect to your server and edit files securely like in your case functions.php file. You’ll need the SFTP credentials first to edit your functions.php file. To get the SFTP credentials you need to contact your hosting provider and simply ask them to give you the SFTP credentials (username / password). Once you have the credentials then please follow this article to connect to the SFTP client https://help.one.com/hc/en-us/articles/115005585709-How-do-I-connect-to-an-SFTP-server-with-FileZilla-

When you’re connected to your server navigate to \wp-content\themes\x-child and copy functions.php file to your system and paste the above in the file and transfer back the file in the same directory.

To learn more about SFTP please see https://searchcompliance.techtarget.com/definition/SFTP-Secure-File-Transfer-Protocol

Hope this helps!

Thank you Nabeel,

That was helpful, I could understand it a bit better.

I have contacted my server provider and have guided me though the process but I still cant find the specific file they are referring too.

Could you please recomend me a plugin compatible with this theme that will allow me to add social sharing buttoms?

Thanks guys for your help, this can get really frustrating when you dont have a techy background. I appreciate it.

Cheers,

Pablo

Pablo

Hi Pablo,

You can take a look at this article:

Hope it helps :slight_smile:

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