Support » Plugin: Nice Likes » Custom location php not showing

  • Resolved andrewskg

    (@andrewskg)


    Hello,
    Thanks for a neat simple plugin.
    I am having problem with the custom location php code when adding to single.php.

    The code I try is `<?php
    if ( function_exists( ‘nice_likes’ ) ) :
    nice_likes();
    endif;
    ?>

    <?php echo the_ID() ;?>
    `
    I am including the_ID() to check that in fact the file is called. The ID is displayed but the plugin returns nothing. No errors in the console.

    I also tried with <?php do_action( 'nice_likes_custom' ); ?> but it still doesn’t show anything even thought the php file is loaded.

    Please help

    • This topic was modified 1 year, 7 months ago by  andrewskg.
    • This topic was modified 1 year, 7 months ago by  andrewskg.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Andrés Villarreal

    (@andrezrv)

    Hi andrewskg,

    Thank you for writing, I hope you’re doing well.

    We’ve been checking the issue you described, and we can confirm that the plugin’s documentation was not correctly updated. The correct code you need to use is this:

    
    if ( function_exists( 'nice_likes' ) ) :
        nice_likes( array( 'echo' => true ) );
    endif;
    

    However, instead of this method, we recommend to use the nice_likes_custom action like this:

    
    do_action( 'nice_likes_custom' );
    

    There was an error in the 1.0.5 version of the plugin that prevented the action from working correctly. However, this has been fixed for the current version (1.0.6), so after you update the plugin, it should work fine for you now. Just remember that this method requires to select the “In a custom location” option for the “Position” setting in the plugin’s admin page.

    Please let us know if this solves the issue on your end.

    Best,

    Andrés.

    Hi Andrés,

    Unfortunately, updating to 1.0.6 didn’t help.

    1. I have selected “In a custom location” in position via WP-Admin

    2. This is my code:

               BEFORE LIKES CODE --
                <?php do_action( 'nice_likes_custom' ); ?>
                -- AFTER CODE --
                <?php echo the_ID() ;?>

    3. The output on page is completely missing the nice likes, and only prints “BEFORE LIKES CODE — — AFTER CODE — 1547”

    4. There are no errors with WP_DEBUG on and also nothing in the chrome console

    • This reply was modified 1 year, 7 months ago by  andrewskg.

    to update you, the alternative WORKS:

     <?php if ( function_exists( 'nice_likes' ) ) :
                    nice_likes( array( 'echo' => true ) );
                endif; ?>
    Plugin Author Andrés Villarreal

    (@andrezrv)

    Hi andrewskg,

    Thanks for the follow-up. Are you trying to display likes in single post views, or you want want them to appear in a custom post type view? I’m asking this because custom post types may require some additional integration to work fine with the action hook. If that’s not the case and you’re simply trying to show likes for posts, you need to make sure to check the “Posts” option for the “Show Likes in” setting.

    Please let me know if this helps.

    Best,

    Andrés.

    Hi Andres,

    I am trying to use it on custom-post-types.

    So to recap, the ” <?php do_action( ‘nice_likes_custom’ ); ?> ” doesn’t work, but the “nice_likes( array( ‘echo’ => true ) );” works fine.

    It would be nice if both versions can work with custom-post-types seamlessly in the future, but in case, I can use the nice_likes() for now – thanks very much for the plugin.

    Plugin Author Andrés Villarreal

    (@andrezrv)

    Hi andrewskg,

    Sorry for the delayed answer. The plugin doesn’t fully support Custom Post Types by design, since each one can be implemented on a very different way, depending on the project. However, we provide hooks to deal with multiple scenarios.

    For example, you can add support for custom location (using do_action( 'nice_likes_custom' )) in the single view of your custom post type by adding something like this to a plugin or the functions.php file of your theme:

    
    add_filter( 'nice_likes_apply_to_other', 'custom_apply_to_other' );
    /**
     * Display likes in custom location for "movie" custom post type.
     */
    function custom_apply_to_other( $apply ) {
    	return $apply ?: is_singular( 'movie' );
    }
    

    This example assumes you have a post type called “movie”. You just need to replace the “movie” keyword with the actual internal name of your custom post type. That’s the same value for the first parameter you passed to the register_post_type() function when you created the post type.

    For further reference, you can also check this link: https://codex.wordpress.org/Function_Reference/register_post_type

    Please let me know if this helps.

    Best,

    Andrés.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom location php not showing’ is closed to new replies.