Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    Howdy,

    While we allow individual posts to having sharing buttons on an archive page when that is opted-in via Settings->Sharing, we do not have plans at this time to add sharing buttons to specifically share an archive page.

    Cheers!

    Thread Starter ameraz

    (@ameraz)

    Thanks for your reply Brandon, look this is my site: https://birchalltea.co.uk
    I really need this feature and although it’d be really cool if you were to include this at some point and make Jetpack flexible, what I really want to know is if there’s any way of hooking into the plugin to enable the printing of the buttons in archive pages, even if I’d have to put together my own Open Graph meta.
    Also, Im using Jetpack sharing feature for my products and the og:type is showing as article instead of product, might be worth taking a look into that.

    Cheers!

    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    For the og:type, we don’t have any code to determine what the type should be, other than is_singular() should be article, is_author should be profile, etc).

    You can filter our og tags to replace this as needed, e.g.

    add_filter( 'jetpack_open_graph_tags', 'custom_og_type' );
    function custom_og_type( $tags ) {
    $tags['og:type'] = "product";
    }

    and adding a conditional, either within the function or to fire the add_filter as needed.

    Back to the original issue, we’ll still output og tags on archive pages (though I’ve personally have had to dig into them to know if there are any notable things about them specifically).

    Looking in modules/sharedaddy/sharing-service.php, I don’t think there’s a way to hook it in as it is built now. The sharing_display function actually handles the output and it is set to return early if the global $post variable is empty and later in the code, it assumes there is a current post.

    If I may, what’s the particular use case for sharing archive pages? Knowing why folks want certain features can help inform us as we look at future development.

    Cheers!

    Thread Starter ameraz

    (@ameraz)

    Thanks again for coming back.

    Well, just as the Open Graph suggests with the og:type product.group and having the resources to feed a Product Category – by that I mean having the $term‘s name, description and image, I think that providing the ability to share an Archive wether its Products or blog articles seems to be yet another interesting way of engaging with our audience.

    Although not yet in practice, with the combination of these functions I’ve managed to get my Open Graph Meta ready:

    function getUrl() {
    	$url  = isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http';
    	$url .= '://' . $_SERVER['SERVER_NAME'];
    	$url .= in_array( $_SERVER['SERVER_PORT'], array('80', '443') ) ? '' : ':' . $_SERVER['SERVER_PORT'];
    	$url .= $_SERVER['REQUEST_URI'];
    	return $url;
    }
    
    add_action('wp', __NAMESPACE__ . '\\pmt_remove_jetpack_og_meta');
    function pmt_remove_jetpack_og_meta() {
    	if (!is_admin()) {
    		if ( is_front_page() || is_home() || is_archive() || is_shop() || is_product_category() || (is_woocommerce() && is_tax()) ) {
    			add_filter( 'jetpack_enable_open_graph', '__return_false' );
    		}
    	}
    }
    
    add_action('wp_head', __NAMESPACE__ . '\\pmtScriptsLoaderHeader' );
    function pmtScriptsLoaderHeader() {
    	if (!is_admin()) {
    		// Set Facebook Open Graph Meta
    		$currentUrl = pmtGetUrl();
    		$fbMetaType = 'website';
    		$fbMetaTitle = get_bloginfo('name');
    		$fbMetaImg = get_template_directory_uri() . '/dist/images/Birchall-Tea.png';
    		$fbMetaDesc =  get_bloginfo('description');
    
    		if (is_front_page()) {
    			$fbMetaType = $fbMetaType;
    			$fbMetaTitle = $fbMetaTitle;
    			$fbMetaImg = $fbMetaImg;
    			$fbMetaDesc = $fbMetaDesc;
    		} elseif (is_shop()) {
    			$fbMetaType = 'product.group';
    			$fbMetaTitle = "Birchall's Tea Shop";
    			$shop = get_queried_object();
    			$thumbID = get_post_thumbnail_id($shop->ID);
    			$thumbSrc = wp_get_attachment_image_src( $thumbID, 'large');
    			$fbMetaImg = $thumbSrc[0];
    			$fbMetaDesc = $fbMetaDesc;
    		} elseif (is_product_category()) {
    			$fbMetaType = 'product.group';
    			$term = get_queried_object();
    			$tax_archive_title = get_field('tax_archive_title', $term);
    			$fbMetaTitle = $tax_archive_title;
    			$thumbID = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
    			$thumbSrc = wp_get_attachment_image_src( $thumbID, 'large');
    			$fbMetaImg = $thumbSrc[0];
    			$fbMetaDesc = $term->description;
    		} elseif (is_woocommerce() && is_tax()) {
    			$fbMetaType = 'product.group';
    			$term = get_queried_object();
    			$tax_archive_title = get_field('tax_archive_title', $term);
    			$fbMetaTitle = $tax_archive_title;
    			$thumb = get_field('pa_thumb', $term);
    			$fbMetaImg = $thumb['sizes']['medium'];
    			$fbMetaDesc = $term->description;
    		} elseif (is_home()) {
    			$fbMetaType = 'website';
    			$blogPage = get_option('page_for_posts');
    			$blogPageObj = get_post($blogPage);
    			$fbMetaTitle = $blogPageObj->post_title;
    			$thumbID = get_post_thumbnail_id($blogPageObj->ID);
    			$thumbSrc = wp_get_attachment_image_src( $thumbID, 'large');
    			$fbMetaImg = $thumbSrc[0];
    			$fbMetaDesc = $blogPageObj->post_excerpt;
    		} elseif (is_archive()) {
    			$term = get_queried_object();
    			$fbMetaType = 'website';
    			$fbMetaTitle = $term->name;
    			$blogPage = get_option('page_for_posts');
    			$blogPageObj = get_post($blogPage);
    			$thumbID = get_post_thumbnail_id($blogPage->ID);
    			$thumbSrc = wp_get_attachment_image_src( $thumbID, 'large');
    			$fbMetaImg = $thumbSrc[0];
    			$fbMetaDesc = $fbMetaDesc;
    		}
    
    		if ( is_front_page() || is_shop() || is_product_category() || (is_woocommerce() && is_tax()) || is_home() || is_archive() ) { ?>
    			<!-- Facebook Open Graph Meta -->
    			<meta property="og:type" content="<?php echo $fbMetaType; ?>" />
    			<meta property="og:title" content="<?php echo $fbMetaTitle; ?>" />
    			<meta property="og:url" content="<?php echo $currentUrl; ?>" />
    			<meta property="og:description" content="<?php echo $fbMetaDesc; ?>" />
    			<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>
    			<meta property="og:image" content="<?php echo $fbMetaImg; ?>" />
    			<meta property="og:locale" content="en_GB">
    		<?php } ?>
    	}
    }

    But even with this in my Archive Page I can’t get the buttons to be printed:

    if ( function_exists( 'sharing_display' ) ) {
         sharing_display( '', true );
    }
    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    But even with this in my Archive Page I can’t get the buttons to be printed:

    Correct. Currently, sharing display returns out early if it is the global $POST isn’t set: https://github.com/Automattic/jetpack/blob/7c6700150c9ba685a3f988bcf24a9b59e2f7d4d1/modules/sharedaddy/sharing-service.php#L565-L566

    That function would need to be rewritten to account for the possibility of being included on archive pages (outside of individual posts, as they can be shown as part of the excerpt or content of individual posts on an archive page), at least.

    This is not something currently on the roadmap, but would be open to a PR.

    Cheers,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sharing Archive Pages’ is closed to new replies.