WordPress.org

Ready to get started?Download WordPress

Forums

ShareThis: Share Buttons and Social Analytics
Is there a way to include the Query String in the shared URL? (6 posts)

  1. charanjits
    Member
    Posted 1 year ago #

    I have added this plugin on my site. I wan't to share a page along with the query string, but am unable to do so. Any ideas, how I can do that?

    URL of the page:
    http://domain_name.com/page_name/?param=value

    Being shared:
    http://domain_name.com/page_name/

    But I want the complete URL along with query params to be shared:
    http://domain_name.com/page_name/?param=value

    http://wordpress.org/extend/plugins/share-this/

  2. outis
    Member
    Posted 1 year ago #

    Though the generated HTML for the share buttons includes <?php the_permalink() ?>, it isn't evaluated. Instead, the ShareThis plug-in replaces it (using preg_replace()) with the results of get_permalink(). This means you can't replace the <?php the_permalink() ?> in the HTML, and hooking the the_permalink filter won't do any good.

    Original post as follows:

    <div style="text-decoration: line-through;">
    ShareThis' WP plug-in uses the_permalink() for the URLs. It doesn't add the query parameters from the current page by default (as it could cause problems with some sites), but you can create a the_permalink filter to add the query parameters used to request the current page to the permalink URL (the_permalink filter page includes an example on how to append the query string). Note that this will add the query parameters to ALL permalinks, which may cause other issues. If you're not a developer, you may need to get one to help you.

    Another option (one that will only affect the URLs used in ShareThis links) is to edit the HTML tags from within the ShareThis settings page. Replace all occurances of <?php the_permalink(); ?> with <?php echo add_query_arg($_GET, get_permalink()); ?>.
    </div>

  3. charanjits
    Member
    Posted 1 year ago #

    Thanks a lot outis but the solution that you have provided does not work as inside the plugin author has written the following lines:

    if(!empty($tags)){
    				$tags=preg_replace("/\\\'/","'", $tags);
    				$tags=preg_replace("/<\?php the_permalink\(\); \?>/",get_permalink($post->ID), $tags);
    				$tags=preg_replace("/<\?php the_title\(\); \?>/",strip_tags(get_the_title()), $tags);
    				$tags=preg_replace("/{URL}/",get_permalink($post->ID), $tags);
    				$tags=preg_replace("/{TITLE}/",strip_tags(get_the_title()), $tags);
    			}
  4. Cathryn999
    Member
    Posted 1 year ago #

    I have exactly the same issue. The URL I want to share is http://www.mywebsite.com/property?pid=nnnn (where nnnn is variable). But the URL being shared is http://www.mywebsite.com/property, which is invalid and results in an error.

    I have found with another social sharing plugin (addthis) that I can change the code from $url = get_permalink();
    to
    $query_string_list = $_GET;
    if (array_key_exists('attest', $query_string_list)) {
    unset($query_string_list['attest']);
    }
    $url = add_query_arg( $query_string_list, get_permalink());

    and that works, ie it shares the correct URL however that plugin doesn't have a float function and I can't position the buttons where I want them within posts. And whenever it's updated I lose my custom code....

    Any help or advice on this appreciated!

  5. Cathryn999
    Member
    Posted 1 year ago #

    Charanjits, it's working on my site now. I deleted and reinstalled, and am sharing using the "Classic" widget option, not multi-post. You can see it in action here: http://darwinholidayapartments.com/property?pid=5725 - Note Pinterest share is pretty woeful and causes the page to crash but that because of my mung theme. Good luck, hope you get it to work.

    PS I didn't change the code at all, just deleted, reinstalled and selected classic view.

  6. charanjits
    Member
    Posted 1 year ago #

    Thanks a lot Cathryn999 :) Really appreciate your feedback! I will try to do it asap and check out the result.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic