Support » Plugin: ShareThis: Free Sharing Buttons and Tools » Is there a way to include the Query String in the shared URL?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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>

    Thread Starter charanjits

    (@charanjits)

    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);
    			}

    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!

    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.

    Thread Starter charanjits

    (@charanjits)

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Is there a way to include the Query String in the shared URL?’ is closed to new replies.