Skip to Content

pinterest_pin()

Generate a native Pinterest pin button.

PHP March 16, 2017

Usage

PHP
nebula()->pinterest_pin($counts)

Parameters

$counts
(Optional) (Boolean) Whether to show count bubble
Default: false

Request or provide clarification »

Examples

Only show count bubbles to staff.

PHP
<?php nebula()->pinterest_pin(nebula()->is_staff()); ?>

Source File

Located in /libs/Functions.php on line 1176.

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"pre_nebula_pinterest_pin"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

Note: This function contains 2 to-do comments.

PHP
    public function pinterest_pin($counts=0){ //@TODO "Nebula" 0: Bubble counts are not showing up...
        $override = apply_filters('pre_nebula_pinterest_pin', null, $counts);
        if ( isset($override) ){return;}

        if ( has_post_thumbnail() ){
            $featured_image = $this->get_thumbnail_src(get_the_post_thumbnail(get_the_id(), 'full'));
        } else {
            $featured_image = get_template_directory_uri() . '/assets/img/meta/og-thumb.png'; //@TODO "Nebula" 0: This should probably be a square? Check the recommended dimensions.
        }
        ?>
        <div class="nebula-social-button pinterest-pin">
            <a href="//www.pinterest.com/pin/create/button/?url=<?php echo get_page_link(); ?>&media=<?php echo $featured_image; ?>&description=<?php echo urlencode(get_the_title()); ?>" data-pin-do="buttonPin" data-pin-config="<?php echo ( $counts !== 0 )? 'beside' : 'none'; ?>" data-pin-color="red">
                <img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_red_20.png" alt="Pinterest Pin Button" loading="lazy" />
            </a>
            <?php if ( empty($this->pinterest_pin_widget_loaded) ): ?>
                <script type="text/javascript" async defer src="//assets.pinterest.com/js/pinit.js"></script>
                <?php $this->pinterest_pin_widget_loaded = true; ?>
            <?php endif; ?>
        </div>
        <?php
    }

Override

To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

PHP
add_filter('pre_nebula_pinterest_pin', 'my_custom_pinterest_pin', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_pinterest_pin($null, $counts){ //$null is required, but can be ignored
    //Write your own code here

    return true; //Return true to prevent the original function from running afterwords
}

You can completely disable this PHP function with a single line actions:

PHP
 add_filter('pre_nebula_pinterest_pin', '__return_false');