Created
September 5, 2013 21:53
-
-
Save kalkulus/6456737 to your computer and use it in GitHub Desktop.
JAVASCRIPT: Get Wordpress page content element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPageContent(page_type){ | |
if (page_type == 'page'){ | |
if ($('.page:not(body)').length) | |
return $('.page:not(body)'); | |
} | |
else if (page_type == 'post'){ | |
if ($('.post:not(body)').length) | |
return $('.post:not(body)'); | |
else if ($('article').length) | |
return $('article'); | |
} | |
else if (page_type == 'frontpage'){ | |
if ($('.post:not(body)').length) | |
return $('.post:not(body)'); | |
else if ($('article').length) | |
return $('article'); | |
else if ($('.page:not(body)').length) | |
return $('.page:not(body)'); | |
} | |
if ($('#main-content').length) | |
return $('#main-content'); | |
else if ($('.main-content').length) | |
return $('.main-content'); | |
else if ($('#main').length) | |
return $('#main'); | |
else if ($('.main').length) | |
return $('.main'); | |
else if ($('#content').length) | |
return $('#content'); | |
else if ($('.content').length) | |
return $('.content'); | |
else if ($('#opl-content').length) | |
return $('#opl-content'); | |
else if ($('.opl-content').length) | |
return $('.opl-content'); | |
else if ($('#body-content').length) | |
return $('#body-content'); | |
else if ($('.body-content').length) | |
return $('.body-content'); | |
else if ($('#site-content').length) | |
return $('#site-content'); | |
else if ($('.site-content').length) | |
return $('.site-content'); | |
else if ($('.the-post').length) | |
return $('.the-post'); | |
else if ($('.the-page').length) | |
return $('.the-page'); | |
else if ($('[id^=post-]:not(body)').length) | |
return $('[id^=post-]:not(body)'); | |
else if ($('[class^=post-]:not(body)').length) | |
return $('[class^=post-]:not(body)'); | |
return false; | |
} | |
// USAGE | |
<?php | |
page_type = ''; | |
if (is_page()) | |
$page_type = 'page'; | |
if (is_single() || is_archive() || is_category() || is_tag()) | |
$page_type = 'post'; | |
?> | |
var page_content = getPageContent(<?php echo $page_type; ?>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment