Last Updated:

Using WordPress as a framework

WordPress is not only a well-known and good solution for creating blogs, but also a great blogging engine. And that's not all it can do. The power and structure of the engine is such that it allows you to create personal pages or even entire sites in just minutes, using the features and capabilities that WordPress already has.

So, I argue that with the capabilities of WordPress, you can easily and quickly create a professional website, not necessarily in a blog format or a standard WordPress format – simply by using WordPress as a framework. I'm writing this post for people who have minimal knowledge of website building, so I'll be chewing on in detail, perhaps some things that are too basic - for one reason only: I assure you, it's accessible to everyone.

With the capabilities of WordPress, you can easily and quickly create a professional website, not necessarily in a blog format or a standard WordPress format.


What is the essence of the method?

 

When creating our future site, we first need to install its heart - the framework. You need a ready-made installation of WordPress on your site, minimal knowledge of HTML (well, and if there is also a basic knowledge of PHP - generally super), as well as a regular text editor.

Let's create a test.php file and save it at the root of your site (here under the root I mean the same folder where WordPress is installed and where you see files like wp-config.php, wp-login.php or wp-blog-header.php and so on).

Now let's edit our test file.php and add the following lines at the very beginning (top) of it:

<?php include('wp-blog-header.php'); ?>

Now just save the file - done! This simple and unsightly command adds to your now quasi-static pages almost all the endless features, functions, and commands of the WordPress platform.

Let's check to see if it works the way we expect it to. To do this, let's add the following simple HTML code to our test page:

<?php include('wp-blog-header.php'); ?>
<html>
<body>
 <div class="name"><?php bloginfo('name'); ?></div>
 <div class="description"><?php bloginfo('description');
?></div></body>
</html>

Do not forget to save this on your site, and then open this page through the browser (for example, at the address of the www.yoursite.com/test.php, where yoursite.com is the address of your site).

If everything works as it should, you will see the name and description of your blog previously saved through our framework - WordPress. In the same way, we are going to use other built-in functions of this blog engine, but already on our website.


We write a template engine of html-pages in 10 seconds

Okay, moving on. Let's create a simple template page for our text content, which we can then insert into a ready-made template.

Create a new test.php with this minimum code:

<?php include('wp-blog-header.php'); ?>
<?php get_header(); ?>
<!- below starts your text content in HTML format
...
<!- ends your content here ->
<?php get_footer(); ?>

On this page, using the functions get_header() and get_footer(), we make an insert on our page the title and footer (ending) for all pages of the site based on this template. Again, all the specific details of setting up the header and tail of the page will be taken from wordPress settings.

Next, let's make another template page, which we will complicate a little by adding additional, standard for a modern site, elements. For example, the sidebar. Here's what the code for our improved template will look like in this case:

<?php include('wp-blog-header.php'); ?>
<?php get_header(); ?>
<!- below starts your text content in HTML format
...
<!- ends your content here ->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

It's very easy and clear, isn't it? Using the get_sidebar() function, we insert a sidebar into our website. Now let's answer the logical question: what functions are available for use in this way? There are too many such features to try to demonstrate them all in this short article. Here are the most important of them.

Choose, adapt, fantasize!


When does it make sense to use a WordPress-based framework?

 

First, we already know that everything that can be done with WordPress or its installed plugin can be easily used on your customized HTML site. By connecting in the first line of wp-blog-header.php you connect the full power of this blogging CMS.

But here a completely legitimate and logical question arises: why instead of all this voodoo I just do not use my own template within WordPress?

Yes, in many cases it is better to do so.

But a framework-based site has the advantage of retaining full control over the files and structure of your site. On each individual page, you decide which of the entire colossus of WordPress functionality to use in each case - your site will be under your full control with this approach. Yes, almost all of the same can be done with WordPress Page Templates, but it's a heavier and harder-to-control way for a beginner.


And what can I do with this technique?

 

Okay, let's recap, what can we do with our dodgy Wordpress injection?

  • You already have your own WordPress blog, but you want to expand it to a site so that it all works in tandem. Often in this situation, they put a second (parallel) WordPress - this is not always justified and necessary. On the other hand, bare HTML also often looks too primitive, and here you, as a bonus, automatically get the uniformity of the design of the blog and its business card site;

  • You like some kind of theme for WordPress and want to apply it to your small HTML site with minimal effort;

  • For some dynamic inserts or effects on your site when you have no idea how to implement them. You can easily use the ready-made functionality of WordPress or any suitable plugin;

  • For simple content sites, where unnecessary bells and whistles are not needed, but often only one function is missing, for example, comments on a published article.

  • In fact, it's a more advanced substitute for techniques like SSI, which has many advantages when working on large static content projects, but isn't everywhere, whereas right now it's hard to find a hosting that couldn't install a super standard WordPress for the current internet.

  • Finally, it's fun to use something very different from everyone else's. If you're a true geek, this easy way to build a website is a great way to boldly emphasize it once again.

In any case, the era of static sites has definitely passed. And even if you don't think so, and just like Google, are sure that "content is the only king", try the compromise I gave above, which is accessible even to novice webmasters and requires minimal knowledge of HTML.

Here, on the one hand, you retain full control over the structure of your site literally at the cost of inserting one or two additional lines, and on the other hand, you get a site that combines both the main advantages of static HTML sites and modern dynamic CMS.

P.S.: If you suddenly get messages like "Fatal error: Call to undefined function", just check the quotation marks in the code examples above, because when copying in some editors, these quotation marks may be automatically replaced by others. Everywhere they should be single quotes, otherwise it can lead to mysterious errors on your web server.