• 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

    (@hcabrera)

    Hi @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:

    /**
    * 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

    (@vitodumas)

    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

    (@hcabrera)

    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 and alternatives if you don’t want to edit the functions.php file manually for more details.)

    Thread Starter vitodumas

    (@vitodumas)

    Understand…

    There is no parameter for the shortcode.

    I will try the php code.

    Thank you so much.

    Plugin Author Hector Cabrera

    (@hcabrera)

    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

    (@vitodumas)

    I just tried it.
    Unfortunately it doesn’t work.

    Thank you anyway.

    Plugin Author Hector Cabrera

    (@hcabrera)

    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

    (@vitodumas)

    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)
  • You must be logged in to reply to this topic.