0

Lets say i want to detect such thing from the "functions.php" .. to know which Sidebar (or) which Menu is being loaded on current (whatever landed) page, how can i know?

Lets say i have a few pages, with:

  • Page A (with Sidebar: "Today Weather" / Menu: "Apples")
  • Page B (with Sidebar: "To-do List" / Menu: "Oranges")
  • Page C (with Sidebar: "To-do List" / Menu: "Apples")
  • Page D (with Sidebar: "Today Weather" / Menu: "Oranges")

From functions.php, if:

  • there's the Sidebar: "To-do List" used, then i want to just echo "Condition A";.
  • there's the Sidebar: "Today Weathers" used, then i want to just echo "Condition B";.
  • there's the Menu: "Apples" used, then i want to just echo "Condition C";.
  • there's the Menu: "Oranges" used, then i want to just echo "Condition D";.

So the thing here is:

  • How to KNOW the IDs of the things currently loaded.

How to simply do it please.

  • Can I ask why you would need to know this, what are you trying to do that requires this? – Tom J Nowell Jan 14 '15 at 3:18
  • Why, is another story which i fairly suppose. There are a lot possibilities to do with, by knowing what are the things being rendered on a page. Here something like, i have to apply different styles (and DOM structure modifications also) differently on different sidebars (and items inside). I would really appreciate for any help on How. :) – 夏期劇場 Jan 14 '15 at 3:24
  • are you looking to register a new sidebar so you can use more widgetized areas in your theme? or are you looking to have different widgets on different pages? Or are you just trying to echo something on the page to tell you what its using? – NickFMC Jan 14 '15 at 3:25
  • If you need completely different dom structures this implies you are using inflexible JS. CSS isn't an issue if you're using the body_class function to set body tag css classes, as you'd be able to match on the theme/page template in the body tag to apply different CSS on different types of pages – Tom J Nowell Jan 14 '15 at 3:30
  • I understand what it implies to. But please can i just know how to get the ID of current sidebar? Please :S – 夏期劇場 Jan 14 '15 at 3:33
0

Sidebar generator plugin is best solution for your logic?

If you would like to add sidebar even in taxonomy or tag, you would need to create meta field or option field for that.

Below example codes is good for static sidebar!

<?php get_sidebar( 'left' ); ?>
<?php get_sidebar( 'right' ); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.