The dynamic sidebar code you are using uses the page title of the topmost page to name the sidebar. get_the_title
finds the title of the page you are on, not the topmost page title. You need a function that tells you the title of the topmost page in a page hierarchy.
/**
* Get the topmost page title.
*
* @link http://wordpress.stackexchange.com/questions/107843/dynamic-sidebar-conditional
*/
function wpse_107843_get_top_parent_page_title() {
global $post;
$parent_page = get_post( $post->ID );
// Recurse to top parent.
while ( $parent_page->post_parent != 0 )
$parent_page = get_post( $parent_page->post_parent );
return $parent_page->post_title;
}
Related Posts:
- Get list of all registered sidebars
- dynamic_sidebar not rendering sidebar
- Get custom side bar on custom post archive page
- Custom sidebar not showing in the dashboard
- Sidebar Generator? :)
- How can you add a link to a sidebar description?
- unregister_sidebar() in stand-alone theme not working
- Creating a different side bar for single posts than for main page.
- WP for main site and two blogs – implementation
- Adding Multiple Sidebars
- How to increase maximum number of sidebars support?
- How to enable the default sidebar area?
- Sidebar widget not displaying after simple code update.
- Dynamic sidebar rendered in another place than i would like
- Check if sidebar is rendered?
- finding sidebar content in wordpress
- Sidebar only shows up on blog page
- How to troubleshoot Sidebar not being generated
- Why is my custom sidebar always open on the widgets screen in Admin?
- Custom sidebars – get_sidebar() problems
- Content not showing up when using custom template + sidebar
- How to make sidebar float right and site content left
- Call Multiple Sidebars at once
- Why isn’t my registered sidebar showing up in the admin?
- How to wrap the widget content with a div or get the widget title outside?
- Get sidebar parameters (before_widget, before_title, etc.) from within a widget
- Add div class to only one widget
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- Add featured image to sidebar [closed]
- How the WordPress sidebar works
- How to exclude parent category but show child categories?
- Specific and Different Ads for each Post?
- Twenty Ten child theme has post on an inner page. Cant get that page to use my desired template
- Template part vs Sidebar (differences)
- Change sidebar headers from H1?
- Registering multiple sidebars with data from an array
- Best practices: Custom theme sidebar menu – hardcode or widget?
- WordPress widget new instance creates content duplicates
- How to show my sidebar in specific page only?
- How to delete wordpress menu
- CSS Twentyeleven / Sidebar has to be changed IN the CSS Stylesheet. Sidebar on the left side
- WordPress widget/sidebar dividers?
- adding multiple sidebars on pages
- Why does the TwentyTen Theme sidebar have a class called ‘xoxo’?
- Dynamic Sidebar for subcategory of a category
- Can’t see widget areas in my customizer
- How to add a class when there’s no sidebar?
- Custom page sidebar using Template dropdown box
- Sidebar loop – Thematic Framework
- How to have dynamic sidebar content per post
- Sidebar on the wrong side of the page
- author list not linking to correct page
- sidebar parameters (before_widget, before_title) not Working
- 2 dynamic sidebars registered, not showing up
- Custom Sidebar only on single post
- Common side bar for multiple websites
- Cannot retrieve author in sidebar of single.php
- get_sidebar() will not work in footer.php
- Gutenberg get wp registered sidebars
- How do I show breadcrumbs when sidebar is not applied?
- Adding an extra sidebar to your theme
- Why the dynamic_sidebar() call is putted into an ul tag?
- Find sidebar.php in WP 3.9.2
- Is there a way to dump all registered sidebar/widget?
- Sidebar not appearing on page template with custom posts
- get_posts() in secondary sidebar messes up content in primary sidebar
- Get specific sidebars $wp_registered_sidebars [closed]
- How to use full length of the upper part of the content and below of it is a content with a sidebar?
- WordPress – Allow dynamic text to be added into a sidebar upon page creation
- Sidebars are no longer working
- Why is registering a sidebar for each page causing my sidebars to reset?
- is_user_logged_in function in a sidebar not working
- Get or set values in post meta
- The WP home page corrupted after switching to new theme
- How do I fully rid of the 1px wide sidebar border? [closed]
- how do i get my sidebar above content on nanomag theme
- Change Sidebar for rewritten page
- How to get sidebar widgets in leftsidebar template
- Change page layout
- Loading scripts only if a particular shortcode or widget is present
- Need help with theme Business (Modern Themes): sidebar issue
- Undefined index: custom_sidebars
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- I’d like to add an fa icon before a link in my ‘recent post’ side bar [closed]
- Echo there are no posts wp_get_archives
- wp_register_sidebar_widget in loop within a plugin?
- is_home() and is_front_page() not working in sidebar
- Sidebar not visible after changing to new domain
- Resizing Picture
- Sidebar not displaying on custom-page.php
- Add the title of a widget as an ID – for anchor links
- Searchresult sidebar change
- How to hide a Sidebar from other admins?
- Differentiate Between Parent & Child Categories
- How to change font in title of sidebar widget [closed]
- Persistent sidebar.php [closed]
- Sidebar not appearing
- Woo commerce Single Product Sidebar [closed]
- sidebar choice not saved for pages (but saved ok for posts/custom posts) [closed]
- Disappearing Widget Text area