Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Empty the Jetpack Sharing Label input; localize a script to feed it a custom value, wrapped in a p tag.
<?php
/**
* If the Jetpack Sharing label setting has a value, remove it.
* If that field is empty, Jetpack Sharing will not output a set of H3 tags with the label.
*
*/
function sharing_label_clear() {
if ( class_exists( 'Sharing_Service' ) ) :
// read a field from a theme options page
$sharelabel = get_option( 'sharing-options' );
// $label comes from the Sharing_Service class
if ( $label != NULL ) :
$sharelabel['global']['sharing_label'] = '';
update_option( 'sharing-options', $sharelabel );
endif;
endif;
}
/**
* Gets the ACF options field, sharing_label and sends it to a javascript
*
*/
function sharing_label_script() {
if ( class_exists( 'Sharing_Service' ) && !is_single() ) :
$new_label = get_field( 'sharing_label','option' );
$js_loc = get_stylesheet_directory_uri().'/lib/js/';
wp_enqueue_script( 'sharing-set', $js_loc. 'sharing-set.js', array('jquery'), '0.1', false );
wp_localize_script( 'sharing-set', 'ShareLabel', array( 'text' => '<p class="sd-title">'. $new_label .'</p>' ) );
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.