• Resolved revistausina

    (@revistausina)


    Hi. I’m trying to use a conditional tag but it is not working.

    I added a tag ‘n-relacionar’ to the posts I do not want to display the related posts from jetpack, and also added this code to my functions.php

    function jetpackme_no_related_posts( $options ) {
    if ( has_tag( 'n-relacionar' ) ) {
    $options['enabled'] = false;
    }
    return $options;
    }

    But it’s still showing the jetpack related posts. Does anyone know why this code isn’t working?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support darnelldibbles

    (@darnelldibbles)

    Hi there,

    This is the only post that currently have that tag correct?:

    https://revistausina.com/serie/colecao-nana-nelson-angelo-novelli/

    I currently do see related posts as well.

    If you going by the template on the customize related posts page, I would try:

    function jetpackme_no_related_posts( $options ) {
    if ( has_tag( 'n-relacionar' ) ) {
    $options['enabled'] = false;
    }
    return $options;
    }
    add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts' );

    Have you tried that starting point to see if that worked?

    Let me know if that doesn’t work, and I will look further into this for you.

    Thread Starter revistausina

    (@revistausina)

    Hey, yes. That’s what I added to my functions.php, but it’s not working. I would like to have several posts tagged ‘n-relacionar’, which would be easier for me than looking for the post id and uptading to is_single conditional…

    Thanks for the help

    Thread Starter revistausina

    (@revistausina)

    Hey! I have also tried to add the is_single conditional snippet but it doesn’t work as well. Here is the code I used:

    function jetpackme_no_related_posts( $options ) {
    if ( is_single( array( 8034, 7884, 7844, 7770, 8444, 10391, 7936, 8983, 10385, 8047, 8040, 9096, 9450, 9452, 10056, 9497, 10131, 10330 ) ) ) {
    $options['enabled'] = false;
    }
    return $options;
    }
    add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts' );
    

    Does anyone know why?

    Thanks

    Hi @revistausina,

    I’ve had a look at the examples you shared and can’t see any issues there. If none of the conditional tags are working (is_single or has_tag), that points to a broader issue with your code or perhaps the placement in your functions.php file.

    As the Customize Related Posts page mentions, we provide these snippets but are unable to offer assistance in customising them further. Someone else may be able to chime in with a suggestion but otherwise, you may need to ask a developer to have a closer look at why it isn’t working within the code you already have.

    Thread Starter revistausina

    (@revistausina)

    Thanks Gemma, I will try to find someone to check my functions.php then. I wasn’t really trying to customize them further, but only to understand why they don’t work, since the code is right

    Thread Starter revistausina

    (@revistausina)

    The problem is that all other functions inside functions.php work, including a couple from JetPack, for example’jetpackme_more_related_posts’ and ‘jeherve_custom_image’. Only this ‘jetpackme_no_related_posts’ doesn’t work…

    Plugin Contributor James Huff

    (@macmanx)

    Volunteer Moderator

    Are you sure you have added it as Darnell described earlier? https://wordpress.org/support/topic/conditional-tag-for-related-posts-not-working/#post-11364132

    jetpackme_no_related_posts isn’t a function in Jetpack, adding the filter is what creates the function.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional tag for related posts not working’ is closed to new replies.