Moving Sharing Icons

Moving Sharing Icons

If you use a block theme, you no longer need to use the code snippets below to customize the location of the sharing buttons on your site. You can use the Sharing buttons block to place the buttons anywhere you’d like in your theme.

One of the most common requests you send us is “Can we move the Sharing and Like buttons?” By default, the Sharing and Like buttons get printed at the end of the the_content() Loop function, which causes them to display at the end of your post’s text — but that may not be where you want them in your site’s design.

There are actually two ways to move the Sharing buttons and one for the Like button.

Move the Sharing and Like buttons

Jetpack, by default, just attaches this tag to two filters — the_content() and the_excerpt() — so that the Sharing icons get displayed. By editing your theme files, you can move the tag wherever you’d like — we default to attaching it to the filters so that, when the Sharing and Likes modules are activated, the buttons are displayed with no extra work. You’re free to move it around to put the Sharing icons where you’d like; here’s how:

In your functions.php file, add the following:

function jptweak_remove_share() {
    remove_filter( 'the_content', 'sharing_display', 19 );
    remove_filter( 'the_excerpt', 'sharing_display', 19 );
    if ( class_exists( 'Jetpack_Likes' ) ) {
        remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
    }
}
add_action( 'loop_start', 'jptweak_remove_share' );

Find the file for the location where you’d like the sharing icons to appear and insert the following code in the area you want the Sharing or Likes buttons to appear:

if ( function_exists( 'sharing_display' ) ) {
    sharing_display( '', true );
}

if ( class_exists( 'Jetpack_Likes' ) ) {
    $custom_likes = new Jetpack_Likes;
    echo $custom_likes->post_likes( '' );
}

Note that you do not need to display these together; you can put sharing_display() in a separate place from the Likes display codeblock.

Move the Sharing Buttons via jQuery

This method comes via Beau Lebens, a fellow Automattician. He coded this jQuery method for moving the Sharing icons:

jQuery( document ).ready( function( $ ) {
    // Relocate Jetpack sharing buttons down into the comments form
    jQuery( '#sharing' ).html( jQuery( '.sharedaddy' ).detach() );
} );

The #sharing selector is just the DOM location where I want to move the buttons to, and the .sharedaddy one is the container that Jetpack places its buttons in normally. We just detach it from the normal position and then dump it into the new location exactly as it was.

We hope this helps you develop your theme and display things the way you like.

Posted in Tips & Tricks | Tagged , , , | 4 Comments
How to insert another plugin before the Jetpack sharing buttons

How to insert another plugin before the Jetpack sharing buttons

Jetpack sharing buttons are added immediately after the post content. In some cases, you may want to insert a new element between your post content and the sharing buttons. To control whether that element will appear before or after the Jetpack sharing buttons, you will have to change the priority of the filter. In the example below, we’ve added an author box and used the priority 18. As long as the priority is less than 19, it will appear before the sharing buttons.
<?php
/**
* When hooked to either the_content or the_excerpt filters,
* this should append the contents of the `author-box.php`
* file in your theme before the Jetpack ShareDaddy contents
* is added, so long as the priority is 18 or less!
* (as ShareDaddy's sharing options go in at priority 19)
*
* @param string $content The post content as passed to the function
* @returns string The content with the author box appended to it.
*/
function my_author_box( $content = '' ) {
ob_start();
get_template_part( 'author', 'box' );
$author_box = ob_get_clean();
return $content . $author_box;
}
add_filter( 'the_content', 'my_author_box', 18 );
Posted in Developers | Comments Off on How to insert another plugin before the Jetpack sharing buttons
How to use your own resources in the sharing module

How to use your own resources in the sharing module

The sharing module includes an “advanced” option, allowing you to use your own JavaScript and CSS files instead of the files added by Jetpack by default. To get started, go to Settings > Sharing in your dashboard, and check the “Advanced” checkbox at the bottom of the page. Then, you can add your own libraries by adding the following code in a functionality plugin or in your theme’s functions.php file:
function tweakjp_add_sharing_js() {
    wp_enqueue_script( 'sharing-js', WP_SHARING_PLUGIN_URL . 'sharing.js', array( ), 4 );
    $sharing_js_options = array(
	    'lang'   =&gt; get_base_recaptcha_lang_code(),
	    'counts' =&gt; apply_filters( 'jetpack_sharing_counts', true )
    );
    wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options );
}
add_action( 'wp_enqueue_scripts', 'tweakjp_add_sharing_js' );

function tweakjp_add_sharing_css() {
    wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL. 'sharing.css', false, JETPACK__VERSION );
}
add_action( 'wp_enqueue_scripts', 'tweakjp_add_sharing_css' );
Once you’ve checked the option, you will be able to manually enqueue your own sharing js and css files. You’ll note that Jetpack uses the WP_SHARING_PLUGIN_URL constant to build the path to load the libraries. You will have to change that constant by your own when re-enqueueing the sharing libraries. You’ll also notice that you must localize the script and pass over lang and counts values to the sharing.js script.  A working example is included above. Reference
Posted in Developers | Comments Off on How to use your own resources in the sharing module
Skip an Image with Site Accelerator (Formerly Photon)

Skip an Image with Site Accelerator (Formerly Photon)

Once you activate the Site Accelerator module, it will automatically cache and serve all images you’ve added to your posts and pages that have been uploaded to your site.

You can exclude a specific image or an entire page from Site Accelerator easily.

To exclude an entire post or page from using Site Accelerator, you can modify this snippet to fit your needs and add it to your theme’s functions.php or a core functionality plugin:

function no_photon_by_page() {
if ( is_page( 2 ) ) {
add_filter( 'jetpack_photon_skip_image', '__return_true');
}
}

add_action('wp', 'no_photon_by_page');

In this example, Site Accelerator won’t be used on the page with the ID of 2, but you can use any of the WordPress Conditional Functions.

If you’d like to exclude an image from being cached and served by Site Accelerator, you can add the following code to your theme’s functions.php file:

function my_photon_exception( $val, $src, $tag ) {
if ( $src == 'YOUR_IMAGE_URL' ) {
return true;
}
return $val;
}
add_filter( 'jetpack_photon_skip_image', 'my_photon_exception', 10, 3 );

If you’d like to disable Site Accelerator in other specific situations instead, you can check this tutorial.

Posted in Developers | Comments Off on Skip an Image with Site Accelerator (Formerly Photon)
How to remove Jetpack Social options from the New Post screen

How to remove Jetpack Social options from the New Post screen

Note: Publicize is now auto-share and is part of Jetpack Social.

Note: Jetpack Social was formerly known as Publicize.

Jetpack Social adds a set of options right above the “Publish” button in your dashboard. You can hide these options by adding the following code to a functionality plugin, or to your theme’s functions.php:

// Replace with admin_head-post.php for the edit post screen
add_action( 'admin_head-post-new.php', function() {
        global $publicize_ui;
        remove_action( 'post_submitbox_misc_actions', array( $publicize_ui, 'post_page_metabox' ) );
} );

Reference

Posted in Developers | Comments Off on How to remove Jetpack Social options from the New Post screen
Remove Jetpack’s Open Graph meta tags

Remove Jetpack’s Open Graph meta tags

If you’ve activated the Sharing or Jetpack Social modules, Jetpack will automatically add Open Graph meta tags to each one of your posts. These tags are used by Facebook to gather information about the post and build a post preview when one of your readers shares a post on Facebook.

If you already use another plugin to handle Open Graph meta tags on your site, we’ll automatically deactivate Jetpack’s Open Graph meta tags for you, to avoid any duplicates.

If, however, you’ve added these tags to your theme or built your own plugin, you’ll want to add the following code to your theme’s functions.php file or to your plugin, to deactivate Jetpack’s Open Graph meta tags:

add_filter( 'jetpack_enable_open_graph', '__return_false' );
Posted in Developers | Comments Off on Remove Jetpack’s Open Graph meta tags
How to remove the comment form from Carousel View

How to remove the comment form from Carousel View

Sometimes, you may not want your readers to comment on single images. If that’s the case, you can deactivate comments on all attachment pages and in the Carousel view by adding this code snippet to your theme’s functions.php file:
function tweakjp_rm_comments_att( $open, $post_id ) {
    $post = get_post( $post_id );
    if( $post-&gt;post_type == 'attachment' ) {
        return false;
    }
    return $open;
}
add_filter( 'comments_open', 'tweakjp_rm_comments_att', 10 , 2 );
Posted in Developers | Comments Off on How to remove the comment form from Carousel View
Custom post type and metadata support in the REST API

Custom post type and metadata support in the REST API

Posted in Features | Comments Off on Custom post type and metadata support in the REST API
Urgent Bug Fix: Jetpack 2.2.4

Urgent Bug Fix: Jetpack 2.2.4

Dear Jetpack community,

I want to apologize, firstly, for pushing multiple updates out to you in one day. We’ve been doing our very best over the last several months to make sure that our releases are stable and tested in as many disparate environments as possible.

In this case, a bug cropped up because of an oversight in how we loaded a compatibility file for bbPress in Jetpack. It wasn’t caught in testing, which is unfortunate. This is a good example, though, of how we learn from our mistakes, improve our processes, and do better with the next release.

For those users effected by this, we decided it would be better to release Jetpack 2.2.4 as soon as possible to resolve this issue.

As always, please get in touch with us if you run into an issue. We’d be very happy to help!

Posted in Releases | 8 Comments
Spring Has Sprung; Jetpack 2.2.3

Spring Has Sprung; Jetpack 2.2.3

Hello Jetpack community,

We’ve been hard at work on Jetpack over the last couple of weeks. Since releasing version 2.2.2 (which was mainly a bug fix release), we have focused our attention on making sure that Jetpack will play nicely with WordPress 3.6 when it is released. Here are the highlights:

  • Yahoo! Updates API is going away, so Yahoo! has been pulled out of Publicize;
  • The Shortcode module now includes a Bandcamp shortcode;
  • The Audio flash player was removed in 2.2.2 for security reasons. We fixed the vulnerability and reenabled the flash player;
  • The plugin adds Infinite Scroll support to Twenty Thirteen;
  • With Jetpack 2.2.3, the reply-title portion of the comment form can be styled by the theme;
  • and many other things that you can read about in the changelog.

Keep an eye on our news feed! We will be posting some articles on how to use Jetpack-beyond-the-basics, plus some on “getting to know”-the-Jetpack-folks.

Thanks, as always, for following along with us. Here are some updated ways to get in touch:

Posted in Releases | 22 Comments
  • Enter your email address to receive news and updates from Jetpack

  • Join 99.1K other subscribers
  • Browse by Topic