Skip to content

Instantly share code, notes, and snippets.

@robincornett
Last active May 15, 2017 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincornett/1c928950b44526c9b0d668bec59defaa to your computer and use it in GitHub Desktop.
Save robincornett/1c928950b44526c9b0d668bec59defaa to your computer and use it in GitHub Desktop.
Sort the networks/buttons in Scriptless Social Sharing in your own custom order.
<?php
add_filter( 'scriptlesssocialsharing_networks', 'prefix_sort_networks_alpha' );
/**
* A function to reorder the social networks alphabetically for Scriptless Social Sharing.
*
* @author Robin Cornett
* @param $networks
*
* @return mixed
*/
function prefix_sort_networks_alpha( $networks ) {
asort( $networks );
return $networks;
}
<?php
add_filter( 'scriptlesssocialsharing_networks', 'prefix_sort_networks_custom' );
/**
* A function to reorder the social networks for Scriptless Social Sharing.
* Set a value for each network order. 0 is first.
* @author Robin Cornett
* @param $networks
*
* @return mixed
*/
function prefix_sort_networks_custom( $networks ) {
$networks['email']['order'] = 7;
$networks['facebook']['order'] = 1;
$networks['google']['order'] = 2;
$networks['linkedin']['order'] = 4;
$networks['reddit']['order'] = 0;
$networks['twitter']['order'] = 6;
$networks['pinterest']['order'] = 5;
uasort( $networks, 'prefix_set_scriptless_sort_order' );
return $networks;
}
/**
* Custom comparison function to sort the networks.
* @param $a
* @param $b
*
* @return bool
*/
function prefix_set_scriptless_sort_order( $a, $b ) {
return $a['order'] > $b['order'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment