(just got reccommended to post this over here from stack overflow…)

I am just starting with WordPress (defecting from Joomla)- having a bit of difficulty getting started.

One thing I am trying to do is make a custom plugin that allows the user to add custom backgrounds to the site, based on the active menu item.

So what I am trying to do is get the active menu id (like ‘menu-item-xx’ that is added to the nav li’s) and active parent menu id so I can add these to the body classes.

Is this something I can get from anything built into WordPress or is this something I will need to make a custom for?

Any pointers most welcome…

UPDATE

I have solved this now with a custom function that you can find below

4 Answers
4

From my comment earlier: Use the body_class() function in your header.php file or wherever your body tag is, e.g. <body <?php body_class(); ?>>. This will give you an output with a bunch of classes on the body that you can then use in your CSS. For example, <body class="page page-id-114 page-parent page-template-default logged-in admin-bar">. You can also use the body_class filter to add more classes. If you want to add the slug, for instance, you would global $post and then use $post->post_name.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *