Hi Ben,
I recently needed to make a shortcode for my custom needs, I created it and it works perfectly. However I experience a visual problem – for some reason it appears above the h3 in a widget, not inside it.
I created that shortcode (it either generates an affiliate link or shows a contact form is there is no data to generate a link):
//shortcode booking
function booking_shortcode() {
echo '<div class="moneyzbefore"><p>';
if (has_term(198 /* Посуточно */, 'portfolio-type')) { echo "от ";} ?> <?php $number = get_meta('value price'); echo number_format($number); ?> руб. <? if (has_term(198 /* Посуточно */, 'portfolio-type')) { echo " в сутки";};
if (($category != 'отель') && (!has_term(194 /* Продажа */, 'portfolio-type')) && (!has_term(198 /* Посуточно */, 'portfolio-type')) ) { echo " в месяц";};
echo '</p></div>';
$domain = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$host = parse_url($domain, PHP_URL_HOST);
$hotelid = get_meta('booking_ref');
$acity = get_meta('place');
//SOCHI
if ($host == 'sochi.asp.sale') {
if ($acity == 'krasnaya-polyana') {
$bcity = 'city=-2935951';
} else if ($acity == 'esto-sadok') {
$bcity = 'city=-2906048';
} else if ($acity == 'chvizhepse') {
$bcity = 'city=-2900142';
} else if ($acity == 'rosa-khutor') {
$bcity = 'city=-2906048';
} else if ($acity == 'adler') {
$bcity = 'city=-2874290';
} else if ($acity == 'sochi') {
$bcity = 'city=-3006514';
} else if ($acity == 'kudepsta') {
$bcity = 'city=-2939646';}
}
//PSKOV
else if ($host == 'pskov.asp.sale') {
$bcity = 'city=-2989168';
};
if ($hotelid != null) {
echo '<a target="_blank" class="bookitafter" href="*Login to see link . $bcity . '&highlighted_hotels=' . $hotelid . '">Бронировать</a>';
}
else {
echo (do_shortcode('[contact-form-7 id="6859" title="BRONBEZBOOK"]'));
}
}
add_shortcode('booking_sc', 'booking_shortcode');
Than i pasted my shortcode into a text widget with [booking_sc].
You can see it on that example page here: *Login to see link e/nedvizhimost/esto-sadok/posutochno/otel-dolina-960/
it’s a first widget with button. for some reason as I said shortcode appears above widget title and container. Do you know how do I fix it?