Skip to content

Instantly share code, notes, and snippets.

@elias1435
Last active September 12, 2022 16:49
Show Gist options
  • Save elias1435/5355de35c457adae9df2f015216668ff to your computer and use it in GitHub Desktop.
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
<?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