How to add body class in Wordpress if the page is being viewed in an iframe?

From the post How to identify if a webpage is being loaded inside an iframe or directly into the browser window? I understand you can detect whether or not your page is being viewed through a frame or not.

Using a WordPress site. I'd like to append a body class tag to my site dependent on it's view. I'm doing this so I can tweak the styling. I understand this can't be done via PHP and you need to use JavaScript.

Can somebody walk me through an example of how I can add my body class with this?

if (top === self) { not iframe -do nothing } else { in a frame - add body class }

Thanks in advance for the hand holding.


You can do this with jQuery by adding this snippet to your document head. This will add to the body class attribute if the page with javascript code is being embedded through an iframe:

<script type="text/javascript">
$(function() {
  var isInIFrame = (window.location != window.parent.location) ? true : false;
  if(isInIFrame) {

You can view some more source code for this answer on Github

Need Your Help

Rails: How do I call `` in my model and have it persist in the database?

ruby-on-rails activerecord persistence

I'm trying to keep model logic within my model, but I can't get it to perform modifications on itself and have them persist in the database.

annotation = comment?

java annotations

do they by annotation mean a comment in a code with // or /* */?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.