Last active
September 12, 2022 16:49
-
-
Save elias1435/5355de35c457adae9df2f015216668ff to your computer and use it in GitHub Desktop.
by this code snippet can be add view count for crocoblock jet block plugin. use this snippet to your child theme functions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'single_template', 'update_view_counter' ); | |
function update_view_counter( $single_template ) { | |
global $post; | |
$old_count = get_post_meta( $post->ID, 'sk_view_counter', true ); | |
update_post_meta($post->ID, 'sk_view_counter', ($old_count+1)); | |
return $single_template; | |
} | |
add_action( 'jet-blog/smart-tiles/post-meta/after', 'add_counter_field' ); | |
function add_counter_field( $m ) { | |
global $post; | |
$views = get_post_meta( $post->ID, 'sk_view_counter', true ); | |
$views = ($views)?$views:0; | |
echo '<span class="post__comments post-meta__item jet-smart-tiles__meta-item"><span class="jet-smart-tiles__meta-icon jet-blog-icon"><i aria-hidden="true" class="fas fa-eye"></i></span><span class="post__comments-link">'.$views.'</span></span>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment