Skip Navigation

[Resolved] I want show a block only if this is in a specific page.

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.21 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1237554

Hi,
I want to show a specific block only if this is in a specific page (the page with ID = '18').

I try to write this code (in "function.php" file) but the block "gallery" is "HIDE" in every page!
I don't know why if the current page is the page with ID = "18", the block is HIDE.
This is the code:

add_action('admin_head', 'custom_admin_styles');
function custom_admin_styles() {
if (is_page(18)){
/* SHOW the block "gallery" with "display: block"*/
} else {
/* HIDE the block "gallery" with "display: none"*/
}
}

Thanks for the support.

#1237656

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - as I understand, on frontend you are loading the page with ID 18 and you want to inject some CSS or JS based on that page ID.

What if you try to use the following code and use the wordpress hook "wp_head":

add_action('wp_head', 'custom_admin_styles');
function custom_admin_styles() {
if (is_page(18)){
/* SHOW the block "gallery" with "display: block"*/
} else {
/* HIDE the block "gallery" with "display: none"*/
}
}