Как поставить баннер только на главной странице?
Всем привет. Подскажите, как сделать так, что бы банеер выводился только на главной странице. Сейчас он у меня на всех. Сам баннер делал в смарт баннер и размещал его с помощью сгенерированного кода (шоркод). Вот сайт с баннером http://servicebrand.ru . Тема называется Arise. Спасибо
Добавьте следующий код в файл functions.php
function onwp_shortcode_front_page($atts, $content = null) { $result = ''; extract(shortcode_atts(array( "code" => '', ), $atts)); if(!empty($code)){ if(is_front_page()){ $result = do_shortcode( $code ); } } return $result; } add_shortcode('shortcode_front_page', 'onwp_shortcode_front_page');
затем там где вы выводите свой шарткод, замените на:
[shortcode_front_page code="[ваш_шорткод_для_баннера]"][/shortcode_front_page]
[ваш_шорткод_для_баннера] — шорткод который выводит баннер на всех страницах.
Хочу обратить внимание, что в вашем шорткоде кавычки должны быть одинарные, например:
[shortcode_front_page code="[ваш_шорткод_для_баннера primer='123'][/ваш_шорткод_для_баннера]"][/shortcode_front_page]
Добрый вечер. У меня не получается. Сайт вообще перестает работать. Можешь посмотреть, где ошибка. Спасибо заранее.
1. Вот так выглядит мой файл functions.php
<?php
/**
* emmet functions and definitions
*
* @package WordPress
* @subpackage emmet
* @since emmet 1.0
*/
require get_template_directory() . ‘/inc/theme/init.php’;
/**
* Note: Do not add any custom code here. Please use a child theme so that your customizations aren’t lost during updates.
* http://codex.wordpress.org/Child_Themes
*/
function onwp_shortcode_front_page($atts, $content = null) {
$result = »;
extract(shortcode_atts(array(
«code» => »,
), $atts));
if(!empty($code)){
if(is_front_page()){
$result = do_shortcode( $code );
}
}
return $result;
}
add_shortcode(‘shortcode_front_page’, ‘onwp_shortcode_front_page’);
?>
А вот кусок с шоркодом в файле header.php:
<?php
[shortcode_front_page code=»[smartslider3 slider=2 primer=’123′][/smartslider3 slider=2]»][/shortcode_front_page]
?>
Если вы выводите шорткод в коде, то можно все сделать проще:
if(is_front_page()){ do_shortcode( '[smartslider3 slider=2 primer=123][/smartslider3 slider=2]' ); }
С этим кодом банер вообще пропадает с сайта. Вставлял его в файл functions.php в конце, вот так:
<?php
if
(is_front_page()){
do_shortcode(
'[smartslider3 slider=2 primer=123][/smartslider3 slider=2]'
);
}
?>

нужно вставить не в functions.php а в место где вы выводите баннер(скорее всего это header.php)