Support » Plugin: Scriptless Social Sharing » does not pick up URL

  • Resolved arathra

    (@arathra)


    Great plugin, which works well on most pages.

    But on some pages which use the shortcode and which are also dynamically created it does not pick up the URL, i.e. the link says something like

    https://www.facebook.com/sharer/sharer.php?u=

    Is there a way to add the URL via code in the shortcode?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Robin Cornett

    (@littlerchicken)

    Can you please share more details about what’s going on when this happens? Is it only on specific pages or post types; what else is going on in the content; are you modifying the Scriptless behavior in any way by using filters? Is it only the Facebook button which is affected, or are they all? If you can share a link, that may be helpful as well. I’m currently unable to replicate this issue.

    The URL is retrieved dynamically using a standard WordPress function, and the sharing button URL is generated using that and other data, depending on the button.

    arathra

    (@arathra)

    Hi Robin, thanks for getting back to me. It’s only on one page which is dynamically generated.

    This page shows the buttons added (via do_shortcode) and you can see the URL is not present.

    example page

    Thanks.

    Plugin Author Robin Cornett

    (@littlerchicken)

    According to the source code of that page, it looks like it’s an author archive. By default, this plugin works only on single posts/pages and just retrieves the current post/page URL. In order to use the buttons outside of a single post, especially when working with something that isn’t a post, you’ll need to use some filters to modify the data WordPress retrieves for the plugin. For example, to replace the permalink with the author posts link, which is what I think you would need in this instance, you could use a filter like this:

    
    add_filter( 'scriptlesssocialsharing_get_permalink', 'prefix_add_author_permalink', 10, 3 );
    /**
     * On author archives, return the author posts URL for the sharing buttons links.
     * Otherwise, return the standard URL.
     *
     * @param string $link
     * @param string $button_name
     * @param array $attributes
     * @return string
     */
    function prefix_add_author_permalink( $link, $button_name, $attributes ) {
    	if ( ! is_author() ) {
    		return $link;
    	}
    	$author = (int) get_query_var( 'author' );
    
    	return get_author_posts_url( $author );
    }
    

    Depending on how you are managing the site and this page, you may need to tinker with that, but it’s a start. You can add this code to your theme or to a custom plugin; just please practice safe coding and make sure you have backups. You will likely need to look into similar filters for things like the title (scriptlesssocialsharing_posttitle) and other button attributes. This should help you get started.

    arathra

    (@arathra)

    Hi Robin,

    Thanks so much for this. It looks to be working absolutely fine now. I will continue to test but it seems spot on.

    Many thanks indeed! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.