Hi,
you would rather need the “the_permalink” filter, but that would affect all of WordPress, not only Shariff and probably break something on your local installation.
Just for testing purposes I would probably not consider the hassle to mess around with that.
JP
Of course I would need a custom filter from you for this π
I basically just would like to have this in line 1970
of shariff.php
:
else $output .= ' data-url="' . esc_url( apply_filters('shariff_automatic_url', get_permalink() ) ) . '"';
Then, I could do this in my functions.php
file:
function sp_shariff_automatic_url( $url ) {
return str_replace('http://r.local', 'http://online.com', $url);
}
add_filter('shariff_automatic_url', 'sp_shariff_automatic_url');
That would just be awesome!! I just tested it and it works as expected.
The problem is, if would implement this, any other plugin could modify the share url with this filter, without anybody noticing. This is a little bit too risky for a feature that is not even meant to be used on productive environments. But we could maybe set a constant in the wp-config.php to enable this feature first, just to be safe.
So… I solved it like this:
// get the current page url, no matter where we are on the site (also works for archive pages)
function sp_get_current_url() {
$server = untrailingslashit( $_SERVER['HTTP_HOST'] );
$uri = $_SERVER['REQUEST_URI'];
if( strpos($uri, '/') !== 0 ) {
$uri = '/'.$uri;
}
return 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$server}{$uri}";
}
// do the shortcode and replace the home_url() if the site is in development mode
function sp_get_sharing_buttons() {
$url = sp_get_current_url();
if ('development' === WP_ENV ) {
$url = str_replace(WP_HOME_DEV, WP_HOME_PROD, $url);
}
ob_start();
echo do_shortcode("[shariff url='{$url}' backend='on' lang='en']");
return ob_get_clean();
}
// call this from your template file
echo sp_get_sharing_buttons();