Today I spent a fair while on a quest to display only page content on a WordPress site of mine. The situation is that I’m trying to make a very easily updated marketing website for an online-learning project of mine. I like using a proprietary page slider for WordPress (and other platforms, excluding my Moodle e-learning platform). So, hacky as it is, I opted to spin up a dedicated WordPress site that’d just host the sliders in content-only custom theme template files. Of course, this mandated rolling up the sleeves.
The central problem ended up being that my proprietary wordpress plugin installs some Javascript stuff it needs. I could have tried to figure out how to manually install that stuff, but I wanted something that’d inherit updates of WordPress and the plugin. I’ve found a few examples of doing custom theme templates that show only content, but they lacked the necessary guts to get plugin junk loaded. I’ve adapted those bare-bones templates I’ve seen, along with code selectively cut from my theme’s other files (theme is TwentyFourteen).
Here’s my custom theme page:
<?php
/*
Template Name: Bare Content
*/
?>
<!DOCTYPE html>
<!–[if IE 7]>
<html <?php language_attributes(); ?>>
<![endif]–>
<!–[if IE 8]>
<html <?php language_attributes(); ?>>
<![endif]–>
<!–[if !(IE 7) | !(IE 8) ]><!–>
<html <?php language_attributes(); ?>>
<!–<![endif]–>
<head>
<meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
<meta name=”viewport” content=”width=device-width”>
<title><?php wp_title( ‘|’, true, ‘right’ ); ?></title>
<link rel=”profile” href=”http://gmpg.org/xfn/11″>
<link rel=”pingback” href=”<?php bloginfo( ‘pingback_url’ ); ?>”>
<!–[if lt IE 9]>
<script src=”<?php echo get_template_directory_uri(); ?>/js/html5.js”></script>
<![endif]–>
<?php wp_head(); ?>
</head>
<style type=”text/css” media=”screen”>
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(“__(‘[…]’)”); ?>
<?php endwhile; endif; ?>
<?php
echo “<div style=\”visibility:hidden;\”>”;
wp_footer();
echo “</div>”;
echo “</body></html>”;
?>
This code could probably be a bit more concise. Whatever. Hope that helps someone. If not, it’ll probably end up helping me a few years down the road.