Archived topic
Custom content in sidebar
6 replies · Started by Alberto on November 8, 2017
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 there,
I think using sidebar widgets would be a better choice?
Then yo can use this plugin so that it only displays on certain pages: https://en-ca.wordpress.org/plugins/content-aware-sidebars/
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!