Hi Darryl 🙂
Do you have a link to the page in question? So the slider is running on the homepage but it is also running on all other pages (because I’m presuming the page templates of the theme all call for the same widget?)
There are a few ways you could do this, 1 I can think of would be to use a child theme, create a unique homepage template and then create a unique homepage widget area.
That’s just one way, but if you could send me a link to your site, I’d be able to see what’s happening on the site itself.
Thanks
Hi Akyusa01
Thanks for the feedback.
I’m using a child theme, but I would prefer to leave the page templates as stock as possible and rather do any changes via the functions.php file, hence looking for a solution to inhibit the display of the slider to selected pages.
Hey Darryl,
Give the following a go, your original function wasn’t structured properly to use $post_id, let me know if the following works better:
add_action( 'soliloquy', 'hp_slider' );
function hp_slider() {
if ( is_page(105) ) {
do_shortcode('[soliloquy id="1599"]');
}
}
See: https://codex.ww.wp.xz.cn/Conditional_Tags
Hi Erica
Thanks for the reply!
It still doesn’t work – but at least the website doesn’t break!
I think I need to call the function from the widget? My thinking was to prevent the shortcode from running unless its the correct page. So I’m not sure if do_shortcode() is the correct why to go about it?
Ok, looks like i got it to work.
This is what I needed to do:
1. Enable PHP in my widget by adding this code to the functions.php file:
add_filter('widget_text','execute_php',100);
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
2. Function to run the slider shortcode depending on the page ID:
add_action('soliloquy','hp_slider');
function hp_slider() {
if (!is_page(105)) {
return $html;
}
else {
echo do_shortcode('[soliloquy id="1599"]');
}
}
3. Call PHP function in the widget:
<?php hp_slider(); ?>
Thanks for the help!