Title: Shortcode on index.php
Last modified: May 17, 2020

---

# Shortcode on index.php

 *  Resolved [jarljmr](https://wordpress.org/support/users/jarljmr/)
 * (@jarljmr)
 * [6 years ago](https://wordpress.org/support/topic/shortcode-on-index-php/)
 * Hi Hector. Thank for awesome plugins. I have in use for many year! Thank very
   much!
    I see your snippet for show views in single.php this thread: [https://wordpress.org/support/topic/show-wpp_get_views-with-shortcode/](https://wordpress.org/support/topic/show-wpp_get_views-with-shortcode/)
 * I use:
 *     ```
       /**
        * Registers the shortcode [wpp_views_count].
        *
        * @author Hector Cabrera (https://cabrerahector.com)
        * @return string
        */
       function wpp_views_count_func() {
           if (
               function_exists('wpp_get_views')
               && is_single()
           ) {
               $views_count = wpp_get_views( get_the_ID() );
               return ($views_count == 1) ? '1 view' : $views_count . ' views';
           }
   
           return '';
       }
       add_shortcode( 'wpp_views_count', 'wpp_views_count_func' );
       ```
   
 * I want show count views for index.php whit shortcode. But, this code no show 
   views, except in single.php
 * How i can do?
 * Some way for do show coutviews in frontpage?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years ago](https://wordpress.org/support/topic/shortcode-on-index-php/#post-12849290)
 * Hi [@jarljmr](https://wordpress.org/support/users/jarljmr/),
 * If you want to show the views count of your posts on your homepage you don’t 
   really need a shortcode. Since you’re going to be editing your index.php file
   anyways then you could just use this:
 *     ```
       $views_count = wpp_get_views( get_the_ID() );
       echo ($views_count == 1) ? '1 view' : $views_count . ' views';
       ```
   
 * (This need to be placed somewhere inside [the loop](https://codex.wordpress.org/The_Loop).)
 *  Thread Starter [jarljmr](https://wordpress.org/support/users/jarljmr/)
 * (@jarljmr)
 * [6 years ago](https://wordpress.org/support/topic/shortcode-on-index-php/#post-12865651)
 * Thank Hector. I am using Generatepress and add new element > Hook.
 * This code:
 *     ```
       <?php
       $views_count = wpp_get_views( get_the_ID() );
       echo ($views_count == 1) ? '1 view' : $views_count . ' views';
       ?>
       ```
   
 * Just add ?php and ? for work.
 * Thank Hector.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years ago](https://wordpress.org/support/topic/shortcode-on-index-php/#post-12865789)
 * Awesome, glad to know you were able to work it out 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcode on index.php’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [views](https://wordpress.org/support/topic-tag/views/)

 * 3 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/shortcode-on-index-php/#post-12865789)
 * Status: resolved