Skip to content

Instantly share code, notes, and snippets.

@ihorvorotnov
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihorvorotnov/a306ceb7a4bbf64abb3a to your computer and use it in GitHub Desktop.
Save ihorvorotnov/a306ceb7a4bbf64abb3a to your computer and use it in GitHub Desktop.
Custom pages without WordPress theme
/**
* This is one of the few WordPress constants that truly opens up a wide variety of possibilities for any developer.
* What it does is relatively simple, though: it tells WordPress whether or not to load the theme you’re using, which
* allows you to use all WordPress’s functionality for something that doesn’t look like WordPress at all!
* For example, you can create a file named index_non_wp.php and put this snippet in:
*/
// The next line is commented out to tell WP to not load theme
//define('WP_USE_THEMES', true);
// Loads the WordPress Environment and Template
require('./wp-blog-header.php');
// Fake a 200 OK status header
status_header(200);
// Get first post's title from database using $wpdb object
$title = $wpdb->get_var('SELECT post_title FROM ' . $wpdb->posts . ' WHERE ID = 1');
// Print output, no theme.
echo sprintf('This is a non-WordPress page, but we can use all functionality provided by WordPress. For example, this is the title of the first post: <strong>%s</strong>', esc_html($title));
Now if you pay a visit to http://yourdomain.com/index_no_theme.php, a plain page with some WordPress’s contents will be shown, with no styles, no images, and no markups at all! Needless to say, this certainly allows us to create any kinds of fake pages, with just any kinds of contents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment