Wednesday, May 20, 2015

Drupal social share - Service links

Service links is a Drupal module used to attach social share(like FB, Twitter, etc,..) icons on every pages.

I have attached one video URL ( Drupal 7 Service Links Module - Daily Dose of Drupal episode 103 ) here to get basic set up / Config about this module.


But if you want to attach this option on your custom tpl file / on ajax success. please follow the below steps.

1) Code to use in your tpl file.
$social_block = module_invoke('service_links', 'block_view', 'service_links');
print render($social_block['content']);


2) Code to use in ajax success / ajax call back function.
$social_load = block_load('service_links', 'service_links_not_node>>' . $node_id); // Drupal node ID.
$get_social_array = _block_get_renderable_array(_block_render_blocks(array($social_load)));
$get_social_block = render($get_social_array);

3) Below code used to attach meta details on page for SEO purpose.
$element = array( 
 '#tag' => 'meta',
 '#attributes' => array(
 'property' => 'og:url',
 'content' => 'node/url',
 ),
);
drupal_add_html_head($element, 'og_url');
$element = array(
 '#tag' => 'meta',
 '#attributes' => array(
 'property' => 'og:title',
 'content' => $node->title,
 ),
);
drupal_add_html_head($element, 'og_title');
// This code is to attach image on meta to share.
// Image wont be there on share if its missing.
$element = array(
 '#tag' => 'meta',
 '#attributes' => array(
 'property' => 'og:image',
 'content' => 'your/image/url',
 ),
);
drupal_add_html_head($element, 'og_image');
$element = array(
 '#tag' => 'meta',
 '#attributes' => array(
 'property' => 'og:description',
 'content' => 'some_description',
 ),
);
drupal_add_html_head($element, 'og_description');

No comments:

Post a Comment