Understanding “The Loop” in WordPress


When discussing WordPress, and specifically the development of themes (or creating new page templates inside an existing theme) you inevitably will run up against “The Loop”. The Loop is the framework within which WordPress constructs the content for any given page that user visits, whether that be a static home page or a blog view showcasing recent posts, or anything in between. It may sound a bit complex, but really, it’s just a looping mechanism.

The Loop, at its simplest, is a looping structure just like any other in programming. It iterates through what amounts to a list of all of your site’s content, cycling through your posts or pages, and fetching the requested content from them. At its most complicated, you can run The Loop multiple times, fetch only certain items from certain categories, only items not in certain categories, those published within a date range, or with other particular identifying information.

Every page template within a WordPress theme will likely contain The Loop. It’s one way that the template can search for and acquire content from your pages and posts, which are stored in the database. Let’s take a look at some specifics:

A Basic Example of the Loop

if ( have_posts() ) {
    while ( have_posts() ) {
        // Post Content here

You can see in the above example that it’s really a pretty straightforward setup. The entire thing starts with a conditional, with have_posts checking to ensure that there are, in fact, any posts to find. Then the loop happens – while there are still posts (again using have_posts), it iterates through the next post and calls up the_post – which refers to the one currently being iterated through.

Particular Queries

If your needs are more advanced than simply returning every post that there is on your website, you’ll need to limit your queries. This is where WP_Query comes into play.

Filtering by Category

In the below example, modified from an example in the Codex, we will query for posts that are in the category which has the id of 4. Then, you can see a sample of the contents of the loop itself. Here, we check for posts with a category ID of 4, then, within the .post div, we display the post’s title (linked to the post), the date of the post, the post’s content, and the post’s metadata.

<!-- Query for posts which are in category 4 -->
<?php $query = new WP_Query( array( 'cat' => 4 ) ); ?>

<!-- Begin The Loop -->
<?php if ( $query->have_posts() ) {
      while ( $query->have_posts() ) {
        $query->the_post(); ?>
        <div class="post">
            <!-- Display the Title as a link to the Post's permalink. -->
            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

            <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
            <small><?php the_time( 'F jS, Y' ); ?> by <?php the_author_posts_link(); ?></small>

                         <!-- Display the post content -->
            <div class="entry">
                  <?php the_content(); ?>

                        <!-- Display the post metadata -->
            <p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>

The use of WP_Query can lead to some very customizable results. You can include posts of only one category, or several, or include all except for those from one category or another. You can search and return posts that contain a keyword, or locate posts by ID, use the post_type to show only data from pages, and more. If you want to learn in more depth about WP_Query, take a look at the WP_Query documentation.

Tip: You can get the ID number of a category in several ways. One easy way is to head over to “Posts”, then “Categories” in your WP-Admin. Right click on the desired category name in the list, and save the URL. Then paste it in a text editor or notepad somewhere and take a look. As an example, it might look something like this: http://example.com/wp-admin/term.php?taxonomy=category&tag_ID=4&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory – you’re looking for the tag_ID number!

Filtering by Custom Field Values

The custom fields that are available in WordPress can be fantastically useful, and you may at times also need to filter posts by the values set in those as well. A simple task, but it’s worth showing for beginning WordPress developers (or those who haven’t delved far into custom templates or The Loop) to realize how customizable all of this is. Say that you have a custom field department and you’re looking for posts with the value marketing:

$query = new WP_Query( array('meta_key' => 'department', 'meta_value' => 'marketing') );

Understanding “The Loop”

The truely best way to understand The Loop is simply to use it. Use it to fetch your content in the templates you create for themes, or in the code that you customize in existing templates in existing themes. When you want to do something, filter for certain criteria, run The Loop again – check the The Loop documentation in the Codex, or hit up Google for ideas. The sky’s the limit!

This article was originally found here.

The Complete Guide to WordPress Performance Optimization

Ecommerce software stats by builtwith.com

WordPress can thank its simplicity and a low barrier to entry for this pervasiveness. It’s easy to set up, and requires next to no technical knowledge. Hosting for WordPress can be found for as little as a couple of dollars per month, and the basic setup takes just a half hour of clicking. Free themes for WordPress are galore, some with included WYSIWYG page builders.

Many look down on it, but in many ways we can thank WordPress for the growth of the internet and PHP, and many internet professionals have WP’s gentle learning curve to thank for their careers.

But this ease of entry comes at a cost. Plenty of websites that proudly wear the WordPress badge were not done by professionals but by the cheapest developers. And often, it shows. Professional look and professional performance were afterthoughts.

One of the main points of feedback the owner of an aspiring high-quality website will get from a grudging professional is that performance and a professional look and feel shouldn’t be afterthoughts. You can’t easily paint or stick them over a website. Professional websites should be premeditated.


A famous UK used car dealer, Ling’s Cars, tried a unique way to make a kitsch marketing punchline. Unless you’re REALLY sure about what you’re doing, DO NOT try this at home.

And this starts with…

Choice of Hosting

Typically, new users will go with products that are on the low-cost side, with most of beginner-friendly bells and whistles. Considering the shady business practices by some big industry players in this arena, and the complaints and demands for site migration professionals coming from clients, this is a part of website setup that requires due attention.

We can divide WordPress hosting vendors into a few tiers.

Premium, WordPress-dedicated vendors like Kinsta whose plans start at $100 per month, or even higher-grade managed hosting like WordPress VIP by Automattic, may be worth their salt, but also may be out of reach for many website owners.

Medium tier FlywheelA2 hostingSiteground and Pantheon are among those considered reliable and performance oriented, offering acceptable speed and a managed hosting service for those more price-conscious. Users here may get a bit less hand-holding, but these services usually strike an acceptable balance between a solid setup, price, and options for more advanced users. Not to forget, there is Cloudways, which is a hybrid between VPS and managed hosting. Those with their audience in Europe may look into Pilvia, as it offers a performant server stack and is pretty affordable.

There’s an interesting survey of customer satisfaction with more prominent hosting vendors, published by Codeinwp.

For those of us not scared of the command line, there are VPS and dedicated-server vendors like Digital OceanVultrLinode, Amazon’s LightsailHetzner in Europe, and OVH. Hetzner is a German vendor known for its quality physical servers on offer, somewhat above the price of virtual servers, while OVH offers very cost-efficient virtual servers. For the price-conscious, OVH’s subsidiary Kimsufi in Europe and Canada also offers bargain physical dedicated servers, and Host US has very affordable virtual servers.


With managed hosting, things to look for are a good server stack, good CDN integration, and of course SSD storage. Guaranteed resources, like with A2, are a big plus. The next thing to look for is SSH-access. Tech-savvy users may profit from WP-CLI availability.

When choosing a VPS, the thing to look for is XEN or KVM virtualization over OpenVZ, because it mitigates the overselling of resources, helping guarantee that the resources you bought are really yours. It also provides better security.

Easy Engine is software that can make your entire VPS/WordPress installation a one-hour job.

Regarding the server stack, Nginx is preferred to Apache if we’re pursuing performance, and PHP 7 is a must. If we really need Apache, using Nginx as a reverse proxy is a plus, but this setup can get complex.

Tests performed give PHP 7 a big edge over the previous version. According to fasthosts.co.uk:

WordPress 4.1 executed 95% more requests per second on PHP 7 compared to PHP 5.6.

When choosing your hosting, be aware of negative experiences with some providers that have become notorious.

Software Considerations

Things that usually slow down WordPress websites are bulky, bloated front ends with a lot of static resources and database queries. These issues arise from the choice of theme (and its page builders, huge sliders, etc) — which not only slow down initial loading due to many requests and overall size, but often slow down the browser due to a lot of JavaScript, and stuff to render, making it unresponsive.

The golden rule here is: don’t use it unless there’s a good reason to.

This may seem like a rule coming from the mouth of Homer Simpson, but if you can skip any of the bells and whistles, do so. Be conservative. If you must add some shiny functionality or JS eye candy, always prefer those tailored and coded as specifically as possible for your exact need. If you’re a skilled coder, and the project justifies the effort, code it yourself with minimalism in mind.

Review all the plugins your website can’t live without — and remove the others.

And most importantly: back up your website before you begin pruning!

Data model

If you have a theme where you use a lot of custom posts or fields, be warned that a lot of these will slow down your database queries. Keep your data model as simple as possible, and if not, consider that WordPress’ original intended purpose was as a blogging engine. If you need a lot more than that, you may want to consider some of the MVC web frameworks out there that will give you greater control over your data model and the choice of database.


In WordPress we can build a rich custom data model by using custom post typescustom taxonomies and custom fields, but be conscious of performance and complexity costs.

If you know your way around the code, inspect your theme to find unnecessary database queries. Every individual database trip spends precious milliseconds in your TTFB, and megabytes of your server’s memory. Remember that secondary loops can be costly — so be warned when using widgets and plugins that show extra posts, like in sliders or widget areas. If you must use them, consider fetching all your posts in a single query, where it may otherwise slow down your website. There’s a GitHub repo for those not wanting to code from scratch.

Meta queries can be expensive

Using custom fields to fetch posts by some criteria can be a great tool to develop sophisticated things with WP. This is an example of a meta query, and here you can find some elaboration on its costs. Summary: post meta wasn’t built for filtering, taxonomies were.

get_post_meta is a function typically called to fetch custom fields, and it can be called with just the post ID as an argument, in which case it fetches all the post’s meta fields in an array, or it can have a custom field’s name as a second argument, in which case it returns just the specified field.

If using get_post_meta()for a certain post multiple times on a single page or request (for multiple custom fields), be aware that this won’t incur extra cost, because the first time this function is called, all the post meta gets cached.

Database hygiene

Installing and deleting various plugins, and changing different themes over the lifetime of your website, often clutters your database with a lot of data that isn’t needed. It’s completely possible to discover — upon inspecting why a WordPress website is sluggish, or why it won’t even load, due to exhausted server memory — that the database has grown to hundreds and hundreds of megabytes, or over a gigabyte, with no content that explains it.

wp-options is where a lot of orphaned data usually gets left behind. This includes, but is not limited to, various transients (this post warns of best practices regarding deletion of transients in plugins). Transients are a form of cache, but as with any other caching, if misused, it can do more harm than good. If your server environment provides it, wp-cli has a command set dedicated to transients management, including deletion. If not, there are plugins in the WordPress plugins repo that can delete expired transients, but which offer less control.

If deleting transients still leaves us with a bloated database without any tangible cause, WP-Sweep is an excellent free tool that can do the job of cleaning up the database. Another one to consider is WP Optimize.

Before doing any kind of database cleanup, it’s strongly recommended that you back up your database!

One of the plugins that comes in very handy for profiling of the whole WordPress request lifecycle is Debug Objects. It offers an inspection of all the transients, shortcodes, classes, styles and scripts, templates loaded, db queries, and hooks.

Debug Objects plugin output

After ensuring a sane, performance-oriented setup — considering our server stack in advance, eliminating the possible bloat created by theme choice and plugins and widgets overload — we should try to identify bottlenecks.

If we test our website in a tool like Pingdom Speed Test, we’ll get a waterfall chart of all the resources loaded in the request:


Pingdom Waterfall Chart

This gives us details about the request-response lifecycle, which we can analyze for bottlenecks. For instance:

  • If the pink DNS time above is too big, it could mean we should consider caching our DNS records for a longer period. This is done by increasing the TTL setting in our domain management/registrar dashboard.
  • If the SSL part is taking too long, we may want to consider enabling HTTP/2 to benefit from ALPN, adjusting our cache-control headers, and finally switching to a CDN service. “Web Performance in a Nutshell: HTTP/2, CDNs and Browser Caching” is a thorough article on this topic, as is “Analyzing HTTPS Performance Overhead” by KeyCDN.
  • ConnectSend, and Receive parts usually depend on network latency, so these can be improved by hosting close to your intended audience, making sure your host has a fast uplink, and using a CDN. For these items, you may want to consider a ping tool too (not to be confused with the Pingdom tools mentioned above), to make sure your server is responsive.
  • The Wait part — the yellow part of the waterfall — is the time your server infrastructure takes to produce or return the requested website. If this part takes too much time, you may want to return to our previous topics of optimizing the server, WordPress installation, and database stack. Or you may consider various layers of caching.

To get a more extensive testing and hand-holding tips on improving the website, there’s a little command line utility called webcoach. In an environment with NodeJS and npm installed (like Homestead Improved), installing it is simple:

npm install webcoach -g

After it’s been installed, we can get detailed insights and advice on how to improve our website’s various aspects, including performance:

webcoach command


Caching can make all the difference when managing a WordPress website. There are a few layers and possible ways of caching.

Page Caching

Page caching is caching of the entire HTML output of a web application.

If we can, we should try to test the server-level solutions first, like NGINX caching, or Varnish, or caching systems offered by managed host vendors like Kinsta, Siteground, and others.

Siteground Optimizer

If this doesn’t turn out to be as helpful as we’d like, we may want to consider plugins like WP Super CacheWP Fastest Cache, or the overhauled W3 Total Cache from GitHub. All of these can improve performance, but usually require some experimenting. Badly configured caching solutions can actually harm the site’s performance. W3TC, for example — at least before the overhaul — is known to be maybe the best free caching solution, doing real wonders … when it works. When it doesn’t, it can take your website offline.

WP Rocket is known to be maybe the most praised of the premium caching solutions.

Page caching can improve performance drastically, serving entire websites from RAM, but be aware that it can introduce complications if you have a dynamic website with a cart, or parts that depend on cookies or a personalized front end. It can serve one user’s UI parts to another user, so it usually needs to be tested before being put into production. This especially applies to solutions on non-managed servers, like Varnish or Cloudflare page cache.

Fragment caching

Fragment caching is a solution to think about when dynamic, cookie-dependent websites become hard to cache with a full-page approach, or when we are caching Ajax requests. A good introduction is available here.


Object cache

Object cache means compiling and storing in-memory all the database queries and PHP objects. Some caching plugins try to manage object-cache back ends for us. The back ends used are usually APCu, Memcached and Redis.
They need to be installed on the server.

To go deeper into benchmarking our PHP code and the performance of our object caching, a valuable tool which requires shell access and wp-cli installed is the profile command. We can install it with:

wp package install git@github.com:wp-cli/profile-command.git


wp package install wp-cli/profile-command

(You may need to add the --allow-root flag, depending on the installation.)

Then we can profile the whole load cycle, or drill down to specific hooks, files and classes, their load time and caching ratio.

wp profile command

Browser caching

Browser caching means forcing visitors’ browsers to keep static files in their cache, so they don’t need to get them from our server on repeat visits. cache-control and expires headers are used here. Caching plugins often manage browser caching and setting the headers. Technumero made a guide that goes into more depth.

Static Files

Static files are images, stylesheets, JS code, fonts, media files, etc. We should make sure we compress them, and that we’re leveraging HTTP/2 to serve these files if possible. If our managed hosting doesn’t support HTTP/2, or moving our unmanaged VPS to HTTP/2 is out of reach, the easiest way is to implement a CDN into our stack. CDNs serve our static files from data centers closest to our audience. This decreases latency and usually means taking advantage of their highly tuned infrastructure.

Autooptimize is one plugin that can help manipulate our static assets, and reduce the number of requests, concatenating JS and stylesheet files, minifying them and thus shrinking the page output.

Regarding media files, we should consider compressing/encoding our videos to reduce their size, and serving them through providers like YouTube, to reduce the strain on our servers. Cloud storage providers like Amazon S3 are another good option. Video hosting is out of scope of this article, but WPMUDEV made a handy guide about the topic.

Regarding images, these are often too big for the web. Sometimes the only solution that will allow our server to breathe — and might take a lengthy amount of time — is batch compression through the shell. Imagemagick on Linux has a useful convert tool that allows us to batch compress our images. This example does it recursively with all JPGs in a folder, reducing JPEG quality to 80%, along with other small enhancements, and resizing the images (it should be self-explanatory):

for file in *.jpg; do convert "${file}" -resize 20% -sharpen 3 -sharpen 2 -brightness-contrast "0x26" -quality 80 thumb."${file}"; done

WP Bullet has two excellent guides to batch compress JPG and PNG files.

Apart from that, there’s the Imagify service and the accompanying WordPress plugin to reduce image sizes, EWWW image optimizer, and others…


Other random tips

  • Memorymake sure your installation has enough.

  • XML-RPC and login page can often suffer from automated, scripted brute-force attacks — even if one isn’t a big fish. Even without breaking in, they can waste the CPU cycles. We should try to stop them on the server-level, before our WordPress installation is loaded. If we don’t need the access to xml-rpc.php, we can put this snippet inside our virtual host block on nginx:

    location = /xmlrpc.php {    
        deny all;    

    In Apache:

    <Files xmlrpc.php>
        deny from all

    Plugins like iThemes SecurityWPS Hide login and others can help with this and with changing our login page URL.

    If you’re under brute force attacks and you aren’t protected by a CDN like Cloudflare — or a managed host’s protection — consider a firewall like fail2ban (you should probably have a firewall in place whether under attack or not).

  • WordPress Heartbeat: polling the server while WordPress dashboard is open can slow your server, and make your dashboard unresponsive. Especially if it’s open in multiple browser tabs or by several users. The HeartBeat plugin can help solve that.

  • MAX_INPUT_VARS: when saving posts with lots of meta fields, or variable products with WooCommerce, we may reach a limit of maximum allowed request variables (variables sent by complex WooCommerce products can go into thousands). This can bring down your server. Here’s how to fix it.

  • If your WordPress installation with a big database — especially a WooCommerce installation — starts having issues with speed that you can’t solve otherwise, consider ElasticPress. Some have had luck with it.

  • If you use WordFence, make sure to turn off the Live View feature. It can bring to a halt even a VPS with couple of gigabytes of memory.

  • If you’re logging access to your website — particularly in debug.log in your wp-content directory — mind its size. It can grow to the level of gigabytes and crash your server.

  • If you have system crashes on your server/hosting, core dumps will fill up your storage. Have someone analyze the reasons of those crashes, and then delete those files. You’ll recognize them by patterns that look like core.XXXXXX.

All this said, a repeat warning is in order: before you do any changes to your website, back it up!


I hope this compilation of WordPress optimization tips will come in handy. As sites grow in size, the tricks are harder and harder to retroactively apply. That’s why it’s best to start early, and strive for a maximum effect: apply as many of these techniques before you launch, and you’ll not only have a smooth launch, but also a performant app from day 1 — surely a fantastic experience for all new users.

Make sure you also check out SitePoint’s PWA guide. Making your WP site as PWA as possible from day 0 will help users install it on the home screens of their devices, priming them for repeat visits.

Originally found here .

Veliki Market

U poslednjih nekoliko dana smo realizovali spontanu ideju neformalne grupe stručnih ljudi, te vam ponosno predstavljamo Veliki market – web aplikaciju na WordPress platformi, gde možete potpuno besplatno oglasiti i pretražiti samostalne proizvođače hrane. Usluga je potpuno besplatna i takva će i ostati, a posebnu zahvalnost izražavamo mCloud-u na nesebičnoj donaciji hostinga i registracije domena.

Interactive Tables in WordPress Posts Without Google Sheets

You can add interactive tables in your WordPress posts by using a plugin or HTML. But I don’t suggest plugins as sometimes it can become a hindrance for your site speed. Also, many of the bloggers are not familiar with codding. Then what’s the solution? You can insert tables in WordPress posts without a plugin or HTML coding. You can use Google Sheets for this purpose.

How to Create Table Chart in Google Sheets and what’s its peculiarities?

The table that you are inserting using Google Sheets will retain the below four table features.

1. The table will be interactive that means you can navigate through the rows with your keyboard or mouse.

2. You can control the table length with pagination.

3. Your readers can sort your table if required.

4. You can update the table in Google Sheets and it will be automatically reflected in your WordPress post table.

I never compromise on page speed whether it’s on mobile or desktop. So if you prefer to go ahead with a plugin for inserting beautiful simple tables in your posts, after installation check with Google Page Speed Insight whether it’s not affecting your site loading time.

Finally, one more thing before we start our tutorial. If you monetize your blog, my humble advice is please never compromise on page speed. You can earn threefold more money with a blazing speed site together with a spiced up layout compared to a site with poor page speed performance.

Introduction to Interactive Tables

Google Sheets is a free online application with offline features. So the table that you create by using Google Sheets will be of course free to use on WordPress.

When you insert interactive tables in WordPress posts without a plugin and using a Spreadsheet table, the inserted table will look like and behave as below. If you satisfy with this type of responsive table in WordPress, you can continue with the tutorial.

How to Insert Interactive Tables in WordPress Posts Without Plugin

I am going to use the Google Sheet Table Chart feature here to insert tables in WordPress. So with the help of this tutorial, you can also learn how to use Table Chart in Google Sheets.

The main use of Table Chart in Google spreadsheet is to create a Google Sheet Dashboard as well as publish interactive tables on the web.

It’s one of the charts which is not available in Excel.

Steps to Create Interactive Charts in Google Sheets

Make your table ready in Google Sheets. You can refer our Spreadsheet data above for creating your table. I hope you have some exposure to Spreadsheets. So you may know the term “table”.

Select your data. Then from the Insert menu select “Chart”.

Insert Chart - Table Chart 1

From the “Chart editor” that appears on the right, select “Table Chart” under “Chart type”.

Insert Chart - Table Chart 2

We are now inching towards finishing the steps in Google Sheets to create a Table Chart. Let’s move to the customization part of the table chart menu.

Under “DATA” enable “Use row 1 as headers”. Actually, it depends. In our data, the first row is with the column name aka field label.

Insert Chart - Table Chart Step 3

Move to the next tab in the chart editor labeled as “CUSTOMISE”. There make the following changes to add pagination and for coloring alternative rows.

I prefer to color alternative rows as it makes the table beautiful.

Insert Chart - Table Chart Step 4

In the above enabling “Alternative row colors” will give your table a shaded color in the alternate rows.

The “Show row numbers” will show the row numbers on the left. Click “Pagination” if you want to control page numbers in the inserted table in WordPress and decide the total number of rows to appear on each page under “Page size.”

You have done all the steps in Google Sheets. Now the last step is to insert interactive tables in WordPress posts without a plugin.

Steps to Publish Interactive Charts

To insert the Google Sheet table Chart into your blog post, you require an embed code. How to get that embed code of your just created Table Chart?

Click on the Chart Table that you have just created. You can see a three dotted menu on the right top corner.Insert Chart - Table Chart Step 5

Access this menu and click “Publish chart” to get the following options.Insert Chart - Table Chart Step 6

Go to the “Embed” tab and click “Publish”. Just copy the code and in your blog post insert it. This way you can easily insert tables in WordPress Posts without using a plugin or HTML coding.


In this tutorial we explain how you can install and set up a WordPress multisite to build a network of websites. We assume that you already installed a WordPress Single Site. Moreover we assume you have FTP access to the directory of your WordPress installation, as you need to change some files.

Table of Contents

1. Install WordPress Multisite – the Requirements

Before you start to install the WordPress multisite, please make sure that:

  • You already have a WordPress installation
  • Pretty Permalinks are activated. This means your URLs should not look like this http://example.com/?p=2345, but rather like this http://example.com/my-page
  • All plugins are deactivated
  • Important: you have a backup of your WordPress installation
  • You have FTP access to your WordPress installation

2. Allow Multisite in wp-config.php

The first step is to activate the Multisite feature in the file wp-config.php.

  1. Set up a FTP connection to your website.
  2. Open the file wp-config.php, which is is located in the main directory of your WordPress, and add the line
    define('WP_ALLOW_MULTISITE', true);
    above the line:
    /* That's all, stop editing! Happy blogging. */
    Define WP_ALLOW_MULTISITE in wp-config.php to enable the Multisite feature.
  3. Save the file wp-config.php.

Now you enabled the Multisite feature in your WordPress installation. But you haven’t finished yet. The next step is to install the network.

3. Install the WordPress Network

  1. Refresh the page in your browser and log in to your website.
  2. In the left sidebar under Tools you will find the menu tab Network Setup, where you can configure your WordPress Multisite.Install a WordPress Multisite – Settings page “Create a Network of WordPress Sites”
  3. Decide whether you want to use subdomains for the sites in your network (e.g. site1.example.com) or whether you want to have them installed in subfolders (e.g. example.com/site1).  This setting affects all the sites in your network, you cannot change that later on.  Do you need a site to be mapped to a top level domain (e.g. mydomain.com)? This is possible with domain mapping.
  4. Enter a name for your network in the field Network Title in the section Network Details.
  5. Enter the site admin’s e-mail address.
  6. Click the Install button.

4. Add some code to wp-config.php and .htaccess

WordPress will now provide you with two snippets of code, which you need to add to the wp-config.php and .htaccess files. Both files are located in the root directory of your WordPress.

  1. Set up a FTP connection to your website.
  2. Add the first code snippet to your wp-config.php directly above the line
    /* That's all, stop editing! Happy blogging. */
    The snippet looks like this, but adapted to your own site:
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'My Website');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
  3. Add the second code snippet to the .htaccess file and replace other WordPress rules.
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
  4. Save both files.


5. Menu network administration and the network settings

When you changed the wp-config.php and the .htaccess, log into your WordPress admin area again. In the upper admin bar, you now see the new menu Network Admin. It’s displayed always, so you can always enter the admin area of the network, no matter on which site of your network you are. We take a look at the sub menues later on.

Below the network administration, all sites of the network are listed to which you were added. By clicking on the names, you enter the backends of these sites.

The menu Network Admin of a WordPress multisite
The menu Network Admin of WordPress multisite

And here’s the explanation of the menu tabs in the network administration:

  • Dashboard: Here you can find the widget to add new users and new sites to your network.
  • Sites: On this tab, you can see all sites of your network – similar to the posts and pages. By moving the cursor over the websites, you see for example links to edit, display the dashboard, view, delete, archive or deactivate the sites. Note that you have fewer functions for the main page of your network, as this one always needs to exist and you cannot delete it.
  • Users: Here you can administer the users of your network. In contrast to a single site installation, you can assign the super admin user role. The super admin has access to all sites and can make changes within the whole network. If you want a user to have access to the sites of your network, you need to add the user to each site via the user administration of the sites.
  • Themes: The theme administration. Here you can install and uninstall themes and activate or deactivate them for the whole network.
  • Plugins: Here you can find all installed plugins. You can add new plugins or delete them, you can activate or deactivate them for the whole network.
  • Settings: On this tab you can find and edit the basic settings for your site, for example: the network name and the admin E-Mail address, you can allow user registrations, add new users to the site admins, you can make the themes and plugins menu available for site admins or set the standard language of your sites.

6. Add a new website to the network

A WordPress multisite with only one website doesn’t really make sense. To a WordPress multisite, you can add as many websites as you want – always and any time, so, it needn’t be at the beginning. To enhance your website with a new site, take the following steps:

  1. Go to My Sites → Network Admin → Sites and click Add new.Add a new website to a multisite
  2. Enter the desired website address. In this case, we decided for a network with sub directories. The domain is already given, we just add the sub diretory.Settings for the new website in the multisite network
  3. Define a title of the website. This one is displayed at several positions in your network, for example in the backend as website name in My Sites, but maybe also in the frontend or in meta data like the page title.
  4. Choose a language for the new website.
  5. Choose the admin e-mail address which must be different than the one for the whole network. If there is no user with this e-mail yet, a new user with admin role for this site will be created.
  6. Click the button Add Site. Your new site is to be created and will be displayed in My Sites  → Network Admin → SitesHowever, in order to let others than the current admin administer this new site, you need to add them as user with admin role to this site.

7. Install Plugins and Themes in the WordPress multisite

Install or uninstall plugins or themes in a WordPress multisite network is something only the super admin can do. The site admins within the network can only activate or deactivate them. Well, and site admins can only activate and deactivate plugins in case the super admin checked the box Enable administration menus in the network administration in Settings → Network Settings.

Enable administration menus
Enable administration menus to allow admins to enable/disable plugins.

You can find the plugins administration for the whole network under Network Admin → Plugins, the themes administration under Network Admin → Themes.

Install plugins in a multisite
Install plugins in a multisite and make them available for the whole network

For the site admin, the whole thing looks like the next picture.

The plugins administration as site admin in a WordPress multisite
The plugins administration as site admin in a WordPress multisite

Hint: The admin can activate and deactivate plugins, but he cannot install or uninstall them.

For one of the plugins in our example you can read Network Only. This means the plugin is available only for all sites or for no site. Moreover, it’s the super admin only who can set the settings of this specific plugin, you need to make them in the network administration.

You can find further help to set up your multisite in our documentation category WordPress Multisite 1×1. In case you are setting up a multilingual website, take a look at: MultilingualPress getting started.

– And now about local –

A WordPress multisite can be the answer to managing multiple WordPress websites easily. Once you install WordPress multisite on your server, there’ll be no need to replicate administrative tasks on the backend of a number of individual sites. The sites can all be managed from a single dashboard.

Multisite dashboard

What is WordPress multisite exactly? A multisite is a network of two or more sites that operate off a single WordPress install. All the sites on a multisite setup will use the same WP database, WP directory and WP configuration file. In such a setup, the management of the WordPress install is in the hands of a “Network Administrator”. And the administration of the individual sites on the network is left to the care of the respective Site Admins.

How to Install WordPress Multisite on a Local Server

To begin with, make certain that you have administrator rights to access your computer’s file system. This is because you’ll need privileges to create directories and edit files.

We’ll presume that you’ve installed WordPress on your computer already. But just in case you need help with this, you can always look into our earlier guide.

Note. This is a required step. In order to follow through and install WordPress multisite on your local computer, you first need to have a standard WordPress installation running. Again, please check out our other guide – it’s a step-by-step tutorial, quite easy to follow.

To install WordPress multisite locally and create a network of any number of sites on your own computer, follow these steps:

Before you start:

Choice of URL: Now’s the time to decide whether to install additional sites in a sub-directory or under a sub-domain. It’s important to realize that you cannot change this later.

  • A sub-domain URL for the individual sites will read: site1.YOURSITE.comsite2.YOURSITE.com
  • A sub-directory URL for the individual sites will read: YOURSITE.com/site1YOURSITE.com/site2

On a live server, you can install both under a sub-domain or a sub-directory. Installing a sub-domain on a local host is a little more technical. It involves configuring the XAMPP application to create a sub-domain and then registering it in the operating system software files. In this post, we’ll deal with only a sub-directory installation on the local server.

Enabling the Multisite Feature

1. Adding the multisite feature:

Firstly, open your wp-config.php file and find the line, ‘/* That’s all, stop editing! Happy blogging. */‘ towards the end. Just above this phrase, add this piece of code:

define('WP_ALLOW_MULTISITE', true);

Then save and close the file.

2. Setting up your network:

At this point, you should see a new item in your WordPress dashboard. Specifically, go to Tools > Network Setup. Once there, choose either sub-domains or sub directories.

If you’re going with a sub-domain network on a live server, you’ll need to obtain something called a wild card DNS from your hosting service provider. Since, we’re only doing a sub-directory install on a local server, you do not need any permissions. Fill in the details and then click on install.

Install WordPress Multisite

A few lines of code will be generated, and you need to add them in your wp-config.php file and in your .htaccess file.

After inserting the code, save the files. With this, WordPress Multisite is now successfully installed.

To access your Network Admin Dashboard, you’ll have to login afresh.

3. Adding sites to your network:

At this point, you can start creating sites and adding them to your network by clicking through My Sites > Network Admin > Sites > Add New:

Fill in the details for the individual sites, such as Address, Title and email. Then Click Add Site.

In the same manner, you can add as many sites as you want. You’ll see all the sites in your Network under All Sites.

4. Add themes and plugins:

With multisite in place, a Network Admin can install themes and plugins on multisite. These themes and plugins can be activated across the entire network, or selectively on a per-site basis.

When To Use / Install WordPress Multisite?

In general, multisite works well for a group of sites that fall into a hierarchical framework. Think government and its various departments, a university and its different schools, any national / world organization and its numerous chapters.

It’s also a good fit for a group of related sites that share common resources. For instance, a network of parallel or allied blogs.

To understand this better, check out Harvard Blogs, a free service for the benefit of the Harvard community. Anyone with an email at harvard.edu can create a blog on this WordPress install. Bloggers can simply concentrate on creating and managing content for their blogs, while enjoying the common resources offered by multisite – themes, widgets, multimedia material, spam protection and more.

In short, WordPress multisite helps you manage all your blogs from a single dashboard. You’ll need to install themes, plugins and updates just once and then activate them as required. Not only that, you’ll also save on time and server space. And, if you’re up to handling the technicalities, you can even monetize the network by offering to host other sites on your network.

When WordPress Multisite is Not The Solution?

Does all this mean that WordPress multisite is the best solution for anyone who runs multiple blogs? Of course not. While multisite offers great convenience, it does have some downside to it as well. Individual sites are restricted in their choice of themes, plugins and hosting service. Moreover, not all plugins are multisite compatible, and this can somewhat limit your choice of plugins.

Again, any downtime at the server end will cause the entire network to go down. And, if it happens that any one site on the network experiences a spurt in traffic, it may affect the speed of the other sites in the network.

It’s also important to note that detaching a site from the network or migrating the whole multisite setup sometime in the future may require professional help. And therefore, switching to a multisite arrangement should be done after much careful thought.

Install WordPress multisite: To Conclude

You can use a local multisite as a testing site for any changes to your WordPress install or to test compatibility of any new themes or plugins. You can also work on any project locally, before you push it up to a live server.

Source: multilingualpress.org