Is there a way to grab the list of body classes for X page? I tried:

<?php get_body_class('home'); ?>

but got a console error for function not defined.

  • Any specific reason for this. I can't find anything that does what you need. – Pieter Goosen Jan 30 '15 at 5:05
  • @Pieter It's kind of a silly reason. I'm loading in content from other pages via Ajax and the body class remains the same because that part doesn't change. So I just want to replace the body classes when a certain page is loaded. – Desi Jan 30 '15 at 5:07
  • If I understand you correctly, you will need to check if the current page being loaded in the specific page, most probably checking the value of $post->ID, and if the page being loaded in the specifc page, unset the specific body class. You can change a body class. You have to unset it and set a new body class if needed – Pieter Goosen Jan 30 '15 at 5:16
  • 2
    If you get "function not defined" I bet that you are trying to use that function outside WordPress. Can you post the code for the ajax request, both server and client-side? – cybmeta Jan 30 '15 at 8:16

Your Answer

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

Browse other questions tagged or ask your own question.