Title: Exclude current post
Last modified: June 27, 2024

---

# Exclude current post

 *  [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * (@vitodumas)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/)
 * Hi.
 * How to exclude the visible post in the most popular list using a shortcode?
 * I think I saw an answer that this can be done in the Pro version.
 * How can it be done?
 * Thank you very much for your help.

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17854831)
 * Hi [@vitodumas](https://wordpress.org/support/users/vitodumas/),
 * > I think I saw an answer that this can be done in the Pro version.
 * Not sure where you read this but WordPress Popular Posts doesn’t have a “pro”
   version. The plugin is 100% free.
 * > How to exclude the visible post in the most popular list using a shortcode?
 * This code snippet should do the trick:
 *     ```wp-block-code
       /** * Removes current popular post from the list. * * @param  array  $out * @param  array  $pairs * @param  array  $atts * @return array  $out */function wpp_shortcode_ignore_current_post($out, $pairs, $atts) {	if ( is_single() ) {		$current_object_id = get_queried_object_id();		if ( isset($atts['pid']) ) {			$atts['pid'] = rtrim($atts['pid'], ',');			$atts['pid'] .= $atts['pid'] ? ', ' . $current_object_id : $current_object_id;			$out['pid'] = $atts['pid'];		} else {			$out['pid'] = $current_object_id;		}	}	return $out;}add_filter( 'shortcode_atts_wpp', 'wpp_shortcode_ignore_current_post', 1, 3 );
       ```
   
 * Add it to your theme’s functions.php file and you should be good to go.
 *  Thread Starter [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * (@vitodumas)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17854911)
 * Hi Hector.
 * It must have been in the wrong forum.
 * I have this shortcode stuck in a text widget.
 * [wpp excerpt_length=80 range=’last30days’ limit=6 thumbnail_width=400 thumbnail_height
   =220 stats_views=0 wpp_start=” post_html='{thumb}{title}{excerpt} ‘ wpp_end=”]
 * What should I add?
 * Thank you so much.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17854923)
 * Add that PHP code snippet I posted above to your theme’s functions.php file, 
   or use something like Code Snippets to add it to your site (see Kinsta’s [How to safely work with the functions.php file](https://kinsta.com/blog/wordpress-functions-php/#how-to-safely-work-with-the-functionsphp-file)
   and [alternatives if you don’t want to edit the functions.php file manually](https://kinsta.com/blog/wordpress-functions-php/#2-functionsphp-file-alternatives-that-might-be-better)
   for more details.)
 *  Thread Starter [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * (@vitodumas)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17854931)
 * Understand…
 * There is no parameter for the shortcode.
 * I will try the php code.
 * Thank you so much.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17854942)
 * Correct, there’s no parameter for this kind of functionality. It must be done
   via PHP.
 * If you have any further questions please let me know.
 *  Thread Starter [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * (@vitodumas)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17855985)
 * I just tried it.
   Unfortunately it doesn’t work.
 * Thank you anyway.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17856180)
 * That’s odd, it worked on my end. Please explain in detail what you did so I can
   help you figure out what went wrong.
 *  Thread Starter [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * (@vitodumas)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17856251)
 * I already explained it.
 * I put the code in a plugin that I use to avoid using the functions.
   Since it 
   didn’t do anything, I then did it directly in the functions.php
 * I showed the shortocode used above.
 * Now I deleted cookies and browsing data, and tried again, but it doesn’t work.
   
   I keep seeing entries I shouldn’t see.
 * I never had any problems with the widget, until it was removed and I can’t even
   do anything similar anymore.

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

The topic ‘Exclude current post’ 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/)

 * 8 replies
 * 2 participants
 * Last reply from: [vitodumas](https://wordpress.org/support/users/vitodumas/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/exclude-current-post-23/#post-17856251)
 * Status: not resolved