Site logo

Archived topic

Custom content in sidebar

6 replies · Started by Alberto on November 8, 2017

Viewing posts 1–7 of 7

Hello.
I'm looking for the way to add custom fields to the left sidebar only in certain pages, so I think using conditionals like this may works:

<?php if ( get_post_type( get_the_ID() ) == 'my_cpt' && is_singular() && is_active_sidebar( 'left-sidebar' ) ) { ?>
    //Here goes the custom fields
<?php } ?>

If this is the right way, where must I place this code (any hook?)?
BTW, My custom fields are ACF ones.

Thanks in advance!

Hi Leo.
The problem is not displaying the sidebar on certain pages but displaying my custom fields (added with Advanced Custom Fields)
Is it possible with that plugin?, is not possible without using a plugin?

Regards.

You could put your custom field into shortcodes: https://codex.wordpress.org/Shortcode_API

Then use the plugin Leo mentioned to show/hide text widgets with your shortcodes in them.

Widgets don't accept PHP, so you'd have to go the shortcode route.

Hi Tom.
Thanks for replying!
I'll try as you say and I'll tell you how is going on.

Regards.

Hi!
I'd tried as you said and everything seems to be working fine.

Thanks!

Glad we could help!

This archived topic is closed to new replies.