Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the codepen-embed-script handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-account-protection domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-activity-log domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-admin-ui domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-assets domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the jetpack domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-backup-pkg domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-blaze domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-block-delimiter domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-boost-core domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-boost-speed-score domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-classic-theme-helper domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-compat domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-config domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-connection domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-explat domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-external-connections domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-external-media domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-forms domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-image-cdn domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-import domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-ip domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-jitm domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-jwt domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-licensing domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-masterbar domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-my-jetpack domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-newsletter domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-password-checker domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-paypal-payments domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-plugins-installer domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-post-list domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-post-media domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-protect-models domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-protect-status domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-publicize-pkg domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-search-pkg domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-stats domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-stats-admin domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-subscribers-dashboard domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-sync domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-videopress-pkg domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-waf domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-wp-abilities domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the jetpack-wp-build-polyfills domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170
Notice: Function Automattic\Jetpack\Assets::alias_textdomain was called incorrectly. Textdomain aliases should be registered before the wp_default_scripts hook. This notice was triggered by the woocommerce-analytics domain. Please see Debugging in WordPress for more information. in /home/dh_432dct/themedev.thepixelpixie/wp-includes/functions.php on line 6170 How to add Tweet Count to your Share Button | Pixie Nerd Theme
In late 2015, Twitter deprecated it’s tweet count from their API. Yeah, this kinda sucked.
There is a way to at least count the number of times your Twitter share button is clicked however. There are pros and cons to this method:
Pros
It doesn’t increase your page load time loading external scripts
It updates immediately
Cons
It’s not 100% accurate. It only counts how many times the Twitter share button itself has been clicked. Site visitors can choose not to follow through with the share. This will throw the count off.
It only counts clicks since the script was implemented
Still, if having a click count is important to you, read on (and please remember that the following instructions apply only to WordPress sites).
Step 1: Create your custom Tweet button
Please note that I am assuming that you are using FontAwesome v4 here, and have added the script to enable Tooltips
This code will go on the template page or block where your share buttons live.
<?php
$post_id = $post->ID;
$title = get_the_title( $post_id );
$link = get_permalink( $post_id );
$min_count = 1; // how much number to show if there are no tweets to the post yet
$count = ( $count = get_post_meta( $post_id, 'post_tweets', true ) ) ? $count : $min_count;
?>
<a class="pixie-tweets" href="https://twitter.com/share?text=<?php echo htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8'); ?>%3A&via=YOURTWITTERID&related=YOURTWITTERID&url=<?php the_permalink(); ?>" data-toggle="tooltip" data-placement="top" title="<?php echo $count ?> Tweet/s" class="pixie-tweets" data-id="<?php echo $post_id; ?>">
<i class="fa fa-twitter" aria-hidden="true"></i> Twitter
</a>
Replace “YOURTWITTERID” with the ID for your Twitter page (in my case it’s “pixlpixiagency”. Yours will show on your Twitter home page next to the “@” symbol.
Step 2: The jQuery
You will need to put this code in the footer.php file of your theme, right before the </body> tag.
<script>
jQuery( function( $ ){
var ajax_url = '//www.YOURURL.com/wp-admin/admin-ajax.php';
$('.pixie-tweets').click( function(){ // after clicking Tweet button
var tweetbutton = $(this),
post_id = tweetbutton.attr( 'data-id' ); // get Post ID
$.ajax({ // send the info to your server that the Tweet button has been clicked and where
type:'POST',
url:ajax_url,
data:{'post_id' : post_id, 'action' : 'tweet'},
success:function( data ){
tweetbutton.find('span').text( data ); // return and display the result count
}
});
});
});
</script>
Replace “YOURURL” with the url of your WordPress site (in my case it’s “thepixelpixie”.
Step 3: Increase the count, and show the result
This goes in the functions.php file for your theme
function pixie_tweets(){
$min_count = 1; // what number to show if there are no tweets to the post yet
$count = ( $count = get_post_meta( $_POST['post_id'], 'post_tweets', true ) ) ? $count : $min_count;
// if current user IP address == the IP of the previous user who clicked the button, skip lines 7-10 of code
if( get_post_meta( $_POST['post_id'], 'post_tweets_latest_ip', true ) != $_SERVER['REMOTE_ADDR'] ) {
$count++;
update_post_meta( $_POST['post_id'], 'post_tweets', $count );
update_post_meta( $_POST['post_id'], 'post_tweets_latest_ip', $_SERVER['REMOTE_ADDR'] );
}
echo $count;
die();
}
add_action('wp_ajax_tweet', 'pixie_tweets');
add_action('wp_ajax_nopriv_tweet', 'pixie_tweets');
You can see this in action by hovering over the Twitter share button below.
Have you tried this? Do you have another method? I’d love to hear from you. Please comment below.