treehouse : what would you like to learn today?
Web Design Web Development iOS Development

share buttons and wordpress

  • I am in the process of establishing my first wordpress theme, and within the post loop, I would like to add some share buttons. I am not entirely certain if this can be achieved, but is there a way to, instead of putting in a static URL for the button (ex. facebook like button), put a line of php that dynamically places the URL of the post the buttons are nested in?


    I was looking into the Share This plugin, but I'm unsure if this would be a viable solution for me.

    any help would be greatly appreciated!
  • Yes sir, most certainly is possible although I'm not sure if it's compatible with the Share This link you shared. It looks like their code doesn't have a spot for the URL. Their code grabs it for you.

    However, if you do find a code where you type in the url it's very easily done.

    First you grab whatever the current URL is and create a variable:
    <?php $url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>
    and then you add it where a social media code needs it (the following example is a Facebook Comments code):
    <div class="fb-comments" data-href="<?php echo $url; ?>" data-num-posts="10" data-width="540" data-colorscheme="dark"></div>
  • the only question I have now is where exactly would I place the first line of code?