For my blog posts on my wordpress page i wanted in-content advertising that leads mostly towards other sections of my site. Its works fine as it gets the most reason post from the custom post type 'advertising' to display with the shortcode [in-content]. However last thing i wanted to do is to use advanced custom fields to either have a drop down to select the desired page it should link to, or fill in a custom url. That's the part where it stops working. Whenever i type echo $buttonURL
it crashes my site. Do i have a typo somewhere? I have checked ACF in wordpress multiple times and it does work when i manually replace it with either one of them such as get_field('page_link')
. Can anyone tell me what I'm doing wrong or help me out a little.
Ps. I'll remove the inline styling at a later point when I'm completely done with it. Also I'm more used to including php in html instead of vice versa. However the snippet I used already contained a lot the code of and I just went with it.
<?php
function my_recent_posts_shortcode($atts)
{
$q = new WP_Query(
array('post_type' => 'advertisements', 'posts_per_page' => '1')
);
$list = '<div class="row col-offset-2" style="background-color: #182027;color:white;padding:1em;color:white;">';
$buttonlink = get_field('page_link');
$buttonURL = get_field('custom_url');
if ($buttonURL != '')
{
$buttonfinallink = $buttonURL;
}
else
{
$buttonfinallink = $buttonlink;
}
while ($q->have_posts()) : $q->the_post();
$list .= '<div class="col-md-9">
<h2 style="margin-bottom:0.3em;font-size:16px;">' . get_the_title() . '</h2>
<br /><div style="color:#ccc;font-size:14px;">' . get_field('content') . '</div>
<a href="' . echo $buttonURL . '" class="link" style="margin-top:0.8em; font-size:0.8em;">' . get_field('link_label') . '</a>
</div>
<div class="col-md-3"><img src="' . get_field('image') . '" style="max-height:75px;"></div>';
endwhile;
wp_reset_query();
return $list . '</div>';
}
add_shortcode('incontent-ad', 'my_recent_posts_shortcode');
?>