Laravel Wordpress



Laravel vs wordpress

For starters, WordPress is a system, Laravel is a framework. WordPress is pre-built but offers customizable themes you can use and adjust to your own (or your client’s) needs. Various plugins serve the same purpose and help to make a richer user experience and better content management. Installing WordPress WordPress will be installed within the root of the Laravel project folder. If you have WP CLI installed then run wp core download -path=admin from within the Laravel project. If you don’t have WP CLI installed then download WordPress manually from wordpress.org and extract the contents into your project folder. Install Wordpress as a sub-directory of the Laravel's root, like /wordpress. So you will have /app and /wordpress in the same position. For this you have to create another VirtualHost that points to Wordpress installation.

Earlier this year I gave a talk at WordCamp London 2019. My talk was titled WordPress or Laravel: Why Not Both? and its focus was on building a Laravel application with WordPress being used as a headless CMS. I have based this blog post on my talk.

Brief Introduction to Laravel:

Laravel is an open source PHP MVC application framework first released in 2011 under the MIT license and created by Taylor Ottwell. It is based on the similar Symfony framework and can be used to rapidly build advanced web applications and websites in a way that is extremely scalable and using modern PHP methods.

Main benefits of Laravel and WordPress:

The table above is an overview of some of the benefits of using Laravel for projects, compared against the benefits of using WordPress for a project. By opting to use WordPress as a headless CMS for a Laravel application it is possible to use all of the benefits of Laravel with all of the benefits of WordPress. The only benefit from WordPress that would not be realised with this approach is the presence of many themes and plugins as the site will be served to users via the Laravel framework so the theme and plugins in use will not have any effect on the front end rendering of your application.

Laravel Wordpress

Different types of CMS setup:

A CMS (content management system) is a system that is used to manage the storage of content, and to provide an interface for managing the creation and editing of content within a website or application. The setup of a CMS can be categorized into one of three types: traditional (coupled), decoupled or headless. Historically CMS systems have usually been setup in a coupled architecture but decoupled and headless setups are increasingly common and may soon be the usual solution.

Traditional (Coupled) CMS

In a traditional setup the CMS provides the editing and content management interface and system, and will also render the content on the front end to users. As such the architecture tightly links the back-end to the front-end. Content, assets, and customisations are created, managed and stored on the back-end and rendered by the same CMS on the front-end. This is the standard, default method for deploying most CMS systems such as WordPress, Joomla, and Drupal.

Laravel wordpress rest api

Disadvantages of a coupled CMS

  • Content types and delivery channels are often limited without customisation
  • A limited programming framework.
  • More time is often needed for customisations.
  • Not always developer friendly.
  • Can be a huge drain on server resources.
  • It is easy for code to become messy very quickly due to poor maintenance.
  • A very real chance of a client/editor inadvertently breaking elements of the site.
  • Often less secure and more prone to cyberattacks.
  • Updates are often needed very frequently.
  • If multiple editors are adding content to the site, inconsistency in branding/style can occur.

Decoupled CMS

Wordpress

A decoupled CMS provides an admin interface and tools to manage content, and preprocesses the presentation layer it to be served in another application. Popular implementations for decoupled CMS systems are Gatsby,HUGO and Contentful.

Headless CMS

A headless CMS provides an admin interface and tools to manage content which is then processed in another application. This is similar to the decoupled approach but takes it one step further by providing only the raw data to a third party application rather than preprocessing the front end rendering to be served elsewhere as it the approach used in a decoupled CMS.

Use cases for Laravel with headless WordPress:

You may be asking why you would use WordPress as a headless CMS with Laravel. Why would you not just build your application with Laravel or WordPress? Why would you not just build a custom CMS in your Laravel application? There are many cases where choosing one framework or the other is the better option. But I believe the following are the best use cases for building a Laravel application with headless WordPress:

Wordpress
  • You want to limit the changes that site editors can implement to only content updates.
  • You want to use the Laravel framework for rapid application development.
  • You want to add more flexibility to development in your WordPress projects.
  • You want to use the WordPress CMS admin interface only for editing and adding content, not rendering it.
  • You want to add a blog or news section to a Laravel application where it would be a minor element of the wider application.

Wordpress In Laravel

Advantages of using headless WordPress with Laravel:

Laravel Wordpress Login

  • Complete control over how and where content appears.
  • Fast content delivery – rendering speeds often shortened by cutting out loading of unnecessary JS and CSS files.
  • Easy and secure third party package integrations.
  • Very difficult for clients and editors to inadvertently break the front end.
  • Able to use Laravel MVC principles in development.
  • Clients can still use the familiar and intuitive editing tools built into WordPress to add content.
  • A tidy and clean development structure is possible without a reliance on themes and plugins.
  • Seamless database migration.
  • Laravel is a very powerful and continually evolving PHP framework.

Overview

There are many advantages to using WordPress as a headless CMS in your Laravel applications. But there are some cases where it may not be best suited so you should think about your project as a whole and how it will evolve before deciding on a CMS, framework, and/or application structure. Some alternative solutions to deliver a headless CMS is to use frameworks such as React JS, Symfony, Vue JS, Gatsby, and HUGO.

Laravel And Wordpress

I am working on a prepackaged Laravel with WordPress project named LaraWP which I plan to open source, and will post an update on this blog shortly on its initial completion.

Laravel Wordpress Theme

  • To view the live streamed recording of my WordCamp London talk, click here.
  • To view the slides from my WordCamp London talk, click here.