Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created September 12, 2022 16:51
Show Gist options
  • Save elias1435/3c9c49dcdaacde9d1d1f86138c61da72 to your computer and use it in GitHub Desktop.
Save elias1435/3c9c49dcdaacde9d1d1f86138c61da72 to your computer and use it in GitHub Desktop.
by this code snippet can be add view count for element pro post widget. use this snippet to your child theme functions.php This snippet will only work for skin type "cards" you can change your just change the "cards" below
<?php
add_action( 'elementor/widget/posts/skins_init',function($widget) {
class change_meta_data extends \ElementorPro\Modules\Posts\Skins\Skin_Cards {
public function get_id() {
return 'cards';
}
public function get_title() {
return esc_html__( 'Card', 'elementor-pro' );
}
protected function render_meta_data() {
/** @var array $settings e.g. [ 'author', 'date', ... ] */
$settings = $this->get_instance_value( 'meta_data' );
$postId = get_the_ID();
$views = get_post_meta( $postId, 'sk_view_counter', true );
$views = ($views)?$views:0;
?>
<div class="elementor-post__meta-data">
<?php
if ( in_array( 'author', $settings ) ) {
$this->render_author();
}
if ( in_array( 'date', $settings ) ) {
$this->render_date_by_type();
}
if ( in_array( 'time', $settings ) ) {
$this->render_time();
}
if ( in_array( 'comments', $settings ) ) {
$this->render_comments();
}
if ( in_array( 'modified', $settings ) ) {
$this->render_date_by_type( 'modified' );
}
?>
<span class="elementor-post-views"> <?php echo $views; ?> Views </span>
</div>
<?php
}}
$widget->add_skin( new change_meta_data( $widget ) );
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment