<?php
function generate_company_cta() {
$output = '';
// Check if the post is sponsored
if (get_field('sponsored_post')) {
// Get the sponsor name
$sponsor_name = get_field('sponsor_name');
if ($sponsor_name) {
// Get the company website URL
$company_website = get_field('company_website', $sponsor_name);
if ($company_website) {
// Generate the link
$output = sprintf(
'<a class="company-cta" href="%s" target="_blank" rel="noopener noreferrer">Learn more about %s</a>',
esc_url($company_website),
esc_html($sponsor_name->post_title)
);
}
}
}
return $output;
}
function company_cta_shortcode() {
return generate_company_cta();
}
add_shortcode('company-cta', 'company_cta_shortcode');
?>
<?php