I am working on a site for a recruitment company and they wish to have the 'Apply with LinkedIn' button on each job post.
[[LINK href="https://developer.linkedin.com/plugins/apply"]]https://developer.linkedin.com/plugins/apply[[/LINK]]
Within the plugin there are 2 fields of data that I need to populate dynamically based on the WP post title and the content of a custom field.
This is the plugin:
<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: YOUR_API_KEY
</script>
<script type="IN/Apply" data-companyid="123456" data-jobtitle="JOB TITLE" data-joblocation=JOB LOCATION" data-phone="required" data-email="[email protected]"></script>
I need <em>data-jobtitle</em> to be dynamically populated with the post title
I need <em>data-joblocation</em> to be dynamically populated with the contents of a custom field called <em>Location</em>
There is some reference on a forum post on how to do it here but its beyond me....
[[LINK href="http://developer.linkedin.com/forum/apply-linkedin-plugin-dynamic-data-jobtitle"]]http://developer.linkedin.com/forum/apply-linkedin-plugin-dynamic-data-jobtitle[[/LINK]]
Can anyone help?
Cheers
Sam
Vinod Dalvi answers:
I assume that you can add other fields like api key, email address and company id as you have not asked for it in the question.
To populate post title and location, you will have to <strong>use the_title() and get_post_meta() WordPress functions</strong> to fetch post title and custom field location as shown in following code :
<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: YOUR_API_KEY
</script>
<script type="IN/Apply" data-companyid="123456" data-jobtitle="<?php the_title(); ?>" data-joblocation="<?php echo get_post_meta( get_the_ID(), 'Location', true ); ?>" data-phone="required" data-email="[email protected]"></script>
Sam Cranwell comments:
Super simple! Worked perfectly. Should have got that myself. Thank you.
isp_charlie answers:
send me contact detailt, it need using js for changed. email: [email protected]
isp_charlie comments:
try this:
add this code outside loop post:
<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: YOUR_API_KEY
</script>
and add this into loop:
<script type="IN/Apply" data-companyid="123456" data-jobtitle="<?php the_title()?>" data-joblocation="<?php location here...?>" data-phone="required" data-email="[email protected]"></script>
Dbranes answers:
You can use this shortcode in each post :
[linkedin]
or
[linkedin company_id="123456" api_key="abcd1234" email="[email protected]" phone="required"]
where you can place this into your <em>functions.php</em> in the current theme directory:
function linkedin_callback( $atts ){
$atts = shortcode_atts( array(
'api_key' => 'abcd1234', // API KEY
'company_id' => '123456', // COMPANY ID
'email' => '[email protected]', // EMAIL
'phone' => 'required', // PHONE
), $atts );
global $post;
$job_title = esc_attr( $post->post_title );
$job_location = esc_attr( get_post_meta( $post->ID, 'location', true ) );
ob_start();
?>
<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: <?php echo $atts['api_key'];?>
</script>
<script type="IN/Apply" data-companyid="<?php echo esc_attr( $atts['company_id'] );?>" data-jobtitle="<?php echo $job_title;?>" data-joblocation="<?php echo $job_location;?>" data-phone="<?php echo esc_attr( $atts['phone'] );?>" data-email="<?php echo esc_attr( $atts['email'] );?>"></script>
<?php
return ob_get_clean();
}
add_shortcode("linkedin","linkedin_callback");
Dbranes comments:
If you want to append this automatically to each post content, you can use:
add_action( 'wp_head', 'wp_head_callback');
function wp_head_callback(){
$api_key = 'rEt5p1S5U5J3xZD4akIoy2kL6Tw4blApZ9NEWx_eOyw8SbRQEpl8KJmTCl18IZ0_'; // CHANGE THIS
printf('<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: %s
</script>',
$api_key
);
}
add_filter( 'the_content', 'the_content_callback');
function the_content_callback( $content ){
// MODIFY THIS:
$companyid = '123456';
$phone = 'required';
$email = '[email protected]';
$jobtitle = esc_attr( get_the_title( get_the_ID() ) );
$joblocation = esc_attr( get_post_meta( get_the_ID(), 'location', true ) );
$content .= sprintf( '<script type="IN/Apply" data-companyid="%s" data-jobtitle="%s" data-joblocation="%s" data-phone="%s" data-email="%s"></script>',
$companyid,
$jobtitle,
$joblocation,
$phone,
$email
);
return $content;
}
just make sure you have <strong>wp_head()</strong> in your theme and that you are using <strong>the_content()</strong> to display the content.
somendra meena answers:
hi please paste this code in your theme where you want to show the button but do api key setting
<?php
$postid = get_the_ID();
$query = new WP_Query('post_type=post&p='.$postid.'');
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
?>
<script src="//platform.linkedin.com/in.js" type="text/javascript">
api_key: YOUR_API_KEY
</script>
<script type="IN/Apply" data-companyid="123456" data-jobtitle="<?php the_title()?>" data-joblocation=<?php echo get_post_meta( get_the_ID(), 'Location', true ); ?>" data-phone="required" data-email="[email protected]"></script>
<?php
endwhile; endif;
?>
hope it will work for you
thankyou
Susanta K Beura answers:
Hi
I can do it for you on your site. Lets discuss it on skype. My id is susanta.k
Thank you.
Regards
Susanta
Susanta K Beura comments:
Hi
I can do it for you on your site. Lets discuss it on skype. My id is susanta.k
Thank you.
Regards
Susanta