• Hi. I’m a beginner on wordpress and i tried to use your plugin to add and display a views number in posts meta, but i don’t know how to do it well. I Use ASTRA Theme and this is my Single.php Code:

    
    <?php
    /**
     * The template for displaying all single posts.
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
     *
     * @package Astra
     * @since 1.0.0
     */
    
    get_header(); ?>
    
    <?php if ( astra_page_layout() == 'left-sidebar' ) : ?>
    
    	<?php get_sidebar(); ?>
    
    <?php endif ?>
    
    	<div id="primary" <?php astra_primary_class(); ?>>
    
    		<?php astra_primary_content_top(); ?>
    
    		<?php astra_content_loop(); ?>
    
    		<?php astra_primary_content_bottom(); ?>
    
    	</div><!-- #primary -->
    
    <?php if ( astra_page_layout() == 'right-sidebar' ) : ?>
    
    	<?php get_sidebar(); ?>
    
    <?php endif ?>
    
    <?php get_footer(); ?>
    

    I’m not sure if this is where i have to paste your function code.
    Please Help Me.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @kintango,
    To display a views number in posts meta, ASTRA Theme provides a filter “astra_single_post_meta” which you can use and show the views in post meta.

    For this, you just have to paste this code in the function.php file in “ASTRA Child Theme”.
    This code will work only if ‘Page View Count’ Plugin installs an activate, as we have used this plugin functions and classes.

    add_filter( 'astra_single_post_meta' , 'astra_child_show_views' );
    function astra_child_show_views( $output ) { 
    	if( ! is_callable('A3_PVC::pvc_stats_counter') ) {
    		return $output;
    	}
            //It will return the count in post meta.
    	return $output . A3_PVC::pvc_stats_counter(get_the_ID());
    }

    Note: Don’t paste this code in the original ASTRA theme, the code will be lost as you update the Theme.

    • This reply was modified 4 years, 10 months ago by iankusht.
    • This reply was modified 4 years, 10 months ago by iankusht.
    • This reply was modified 4 years, 10 months ago by iankusht.
    • This reply was modified 4 years, 10 months ago by iankusht.
    Thread Starter kintango

    (@kintango)

    Hi @iankusht Thx for the answer. Can I use Code Snippets plugins to avoid th update lost from Astra ? Or where can I get an Astra child Theme?

    Thread Starter kintango

    (@kintango)

    I Just got it ! Thx

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Views Count on Post Meta’ is closed to new replies.