Elegant Theme’s Divi theme has a nice set of icons built in, including social media icons, so it seems a shame to have to install a social share button plugin to enable sharing for your posts. These plugins often install extra Javascript and icon images which can slow down your site’s page load times. If all you need is a simple (but elegant!) set of share icons at the bottom of your posts, add this code to your single.php template in you Divi child theme:
<ul class="et-social-icons"> <li class="et-social-icon et-social-facebook"> <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode(esc_url(get_permalink())); ?>&t=<?php echo urlencode(esc_attr(the_title())); ?>" target="_blank" title="Share on Facebook" class="icon"> <span><?php esc_html_e( 'Facebook', 'Divi' ); ?></span> </a> </li> <li class="et-social-icon et-social-twitter"> <a href="https://twitter.com/intent/tweet?source=<?php echo urlencode(esc_url(get_permalink())); ?>&text=<?php echo urlencode(esc_attr(the_title())); ?>:%20<?php echo urlencode(esc_url(get_permalink())); ?>" target="_blank" title="Tweet" class="icon"> <span><?php esc_html_e( 'Twitter', 'Divi' ); ?></span> </a> </li> <li class="et-social-icon et-social-google-plus"> <a href="https://plus.google.com/share?url=<?php echo urlencode(esc_url(get_permalink())); ?>" target="_blank" title="Share on Google+" class="icon"> <span><?php esc_html_e( 'Google', 'Divi' ); ?></span> </a> </li> <li class="et-social-icon et-social-pinterest"> <a href="http://pinterest.com/pin/create/button/?url=<?php echo urlencode(esc_url(get_permalink())); ?>&description=<?php echo urlencode(esc_attr(the_title())); ?>" target="_blank" title="Pin it" class="icon"> <span><?php esc_html_e( 'Pinterest', 'Divi' ); ?></span> </a> </li> </ul>
This adds buttons for Facebook, Twitter, Google+ and Pinterest. Here’s what they look like:
Of course, you can easily style the size, colour etc. by tweaking the et-social-icon CSS class in your Divi child theme stylesheet.
Hi Robin,
How can implement this on the “blog module”, a use this module for a custom page for all my posts.
Wow this is awesome, thank you! Is LinkedIn share built in?
Hi, I have a custom layout for every post (used the builder) and would like these buttons, but then let them appear wher i want (In a text module on the page). Is that possible in any way?
Paste the HTML into a Divi code module, not a text module.
Hello, thank you very much for sharing this wonderful code.
I need to add the social buttons in the blog module of my homepage, how can I do it?
Thank you.
Hi thank you for this, we want to use this on specific pages only (not posts), is this possible?
Hi Robin,
Thanks for this! I’m new to coding and pasted the code into a ‘fullwidth code’ module (I don’t even know how to access the stylesheet, haha). The buttons show up but the href links don’t work. I replaced them manually for one of my posts, but would love it to be auto-generated for each post. Do I need to replace certain elements of the ones you provided? Or does it only work in the stylesheet? What am I doing wrong?
Thanks in advance!
Hi Charley. To get the links to appear on each post, you need to add them into the template which generates a single blog post (single.php).
First of all, are you using a child theme? You really should be because it allows you to customise Divi, while still updating the base Divi theme. Here are detailed instructions about how to make a child theme for Divi.
Once you’ve done that:
– enable your child theme in Appearance > Themes.
– copy the single.php template from /wp-content/themes/divi/templates/single.php to /wp-content/themes/your-child-theme-name/templates/single.php.
– go to Appearance > Editor and open single.php.
– paste the social links code above into the editor after the following:
– click Update File to save your changes.
Thanks so much for the quick and thorough reply; great help!
Hi, I’m sorry, but I can’t seem to figure out where in the single.php file to place this code.
Wherever you want them to appear. Maybe just after the post tags?
Very useful. I like a lot simple solutions without plugins. Thank you for sharing.
Hi robin, how do i center the share buttons?
I think you’d have to wrap the whole thing in a div:
then use something like this in your CSS:
Goodmorning, I like to use those share buttons asswell, but in a normal page build with divibuilder. I tried to add the code with the code module in an new section but it didnt work for me. Thanks for your help!
Hi, I’m having problems with mine aligning to the right instead of the left like yours are.
I’m quite new to this theme so just trying to work out where everything is.
Do I need to change something in the CSS?
Is it also possible to have text above it like “Share this”
Thanks for your help
Hi Rachel. Do something like:
Then float the share block to the left (or right) by adding to your CSS:
Hi Robin,
Thanks for your help. I’m still having problems though and the alignment looked different in Chrome than in Brave (I haven’t checked other browers) so there must be something else messing it up. I’m quite new to CSS so not sure.
I have put it up the top for now as it looked strange down the bottom when I couldn’t get anything to align neatly.
Thanks again for your help and if you get a chance perhaps you could see it here and work it out. http://www.facecruit.com.au/is-recruitment-costing-you/
Thanks a lot. Very usefull.
any idea on how to open it in a small window rather a full new window??
Thanks 🙂
Awesome, this helped me out a lot. Thank you for taking the time to explain it to me 🙂
Hi Robin,
Thank you for the informative post, I’m new to coding and I’m wondering how I would go about adding an e-mail icon, any advice?? 🙂
You’ll need to add the following
You’ll also have to add a definition for the et-social-email class to your theme’s stylesheet (style.css) since it isn’t predefined in Divi:
This defines which icon to use for the email share button. You can find others to use in the list of Elegant Theme icons. For example, to use the filled in envelope icon
, use
– (i.e. strip out the
from the unicode number).
This came in real handy, thanks for sharing it.
Hey Robin
It’s Murph – a nice coincidence that I stumbled on this article while searching – just what I need, thanks for this 🙂
You’re welcome. Small world, eh?