building sharing buttons need php for 'this page'

by 4 replies
5
I am building sharing buttons for example
<a href="https://twitter.com/share?url=http%3A%2F%2Fmy-site.com%2Fhome&text=Awesome site:" name="Share on Twitter" target="_blank"><img src="http://my-site.com/wp-content/themes/atahualpa/images/social/Twitter.png"</img></a>

What I want to do is use php in the ?url=

portion to specify the current page.
#programming #building #buttons #page #php #sharing
  • This is how you get the current URL in PHP...

    PHP get current page URL

    So if you implemented the code from the example above, then your button code would look like...

    <a href="https://twitter.com/share?url=<?php echo $currentUrl; ?>&text=Awesome site:" name="Share on Twitter" target="_blank"><img src="http://my-site.com/wp-content/themes/atahualpa/images/social/Twitter.png"</img></a>

    ^ Any page that code goes on would need to have a .php extension, obviously.
    • [ 1 ] Thanks
    • [1] reply
    • Strange when I did that every link comes out as http://my-site.com/index.php?

      This is a Wordpress site and the share buttons are in a widget
      I am using the exec-php plugin to keep the widget from stripping out the php
      • [1] reply
  • if you are using wordpress :
    • [ 1 ] Thanks

Next Topics on Trending Feed

  • 5

    I am building sharing buttons for example <a href="https://twitter.com/share?url=http%3A%2F%2Fmy-site.com%2Fhome&text=Awesome site:" name="Share on Twitter" target="_blank"><img src="http://my-site.com/wp-content/themes/atahualpa/images/social/Twitter.png"</img></a>