Below, you can find notes on the transition from WordPress to Grav, going through various stages. Over time, I will also include support for multi-language and multi-site features.
Let’s now examine how we can transfer our content and how we can set up our theme.
Content Management
After setting up a WordPress website installation, the content management system operates through functions defined in PHP code and database interactions. Plugin and theme functions are executed during this interaction process (via hooks). At every stage, including when you view the admin panel, a series of workflow and control processes take place. When you create content, the function designated for this action becomes active, and the text you enter in the editor is saved as content versions. At this stage, your internet connection and session validity are frequently checked. Once content is saved, the content page’s defined fields (content, title, page path, category, tag, custom fields, etc.) are added to the corresponding database fields. The content displayed to visitors is often presented differently from the record stored in the database. Plugins and theme functions can modify these data values before they are retrieved from the database. For example, if you’re using Visual Composer, the fields and elements you create and add within the plugin are generated according to the defined correspondences1. WordPress gains its power from this well-designed chain of operations.
Grav carries out this process using PHP, particularly through Twig. Theme elements (partials) contained within an extension can also be accessed within the theme itself. Content created in Markdown format, along with YAML definitions specified as blueprint and processed individually in separate files, are both parsed before content is presented to visitors. A database is not required. Since your content is created as a file, it is easily transferable, copyable, and convertible into different formats. Most often, the way content is interpreted is defined within the content file itself. This allows you to view and manage all modifications to your content in one place. Additionally, this parsing process typically occurs on a per-content basis.
I am frequently traveling and often create content drafts via my mobile phone. As a result, I frequently use the Dropbox Paper and Zotero applications, so I normally create ideas in markdown format. Of course, it’s also possible to create content using Markdown formatting via WordPress. However, the process still takes place through the browser.
Theme Management
Twig is a highly favored template engine. There are many template systems available for use on WordPress. However, adding a new layer to the WordPress workflow means extending the process of theme development and maintenance. Particularly when considering personal and small-scale corporate web solutions, this intervention process appears unnecessary and thus impacts resource management.
In short, I believe the theme development process in Grav is both practical and enjoyable. Twig, of course, is the key factor here. This allows any created template to be easily converted into a different theme. This, in turn, positively influences the creative and production process. Taking all these factors into account, Grav becomes a very useful solution for UI designers and web design agencies.
It’s worth reiterating: Grav is not a competitor or alternative to WordPress. The problems they focus on and the ways they solve them are quite different. Given its features, Grav presents a more logical solution for content management processes when content management is considered.
Now, let’s get to the exciting part. You’ve read the thoughts mentioned above and you’d like to migrate your WordPress content to Grav. What’s the next step?
Content Migration
The most challenging part of this process is here. Whether or not your theme is ready, you’ll need to extract your content from the database and convert it into a Markdown format. For this purpose, I previously published the articles “Converting WordPress Content to Markdown” and “Listing Posts and Category Names via WP REST API”.
Let’s first take a look at the fields that a typical WordPress post contains.
As can be seen, there are many fields starting with id and continuing in the order of date, date_gmt, slug, status, tile, content, author, category. These fields can obviously be simplified when requested using the _fields parameter. However, upon closer inspection, metadata definitions and custom fields2, as well as other fields that can be used as part of the content or page during the content presentation process, are not included here. On the other hand, categories and tags are being passed through as id. You can find different solutions regarding this topic in the article titled Post Listing and Category Names with WP REST API.
Now, let’s take a look at the post content I use with Grav.
[raw]
---
title: 'WordPress - GRAV CMS Geçişi'
date: '02-09-020 09:05'
taxonomy:
category:
- grav
- wordpress
- markdown
slug: wordpress-grav-cms-gecisi
routes:
default: /wordpress-grav-cms-gecisi
canonical: /posts/2020/09/wordpress-grav-cms-gecisi
---
## Content
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Elit ullamcorper dignissim cras tincidunt lobortis. Sit amet consectetur adipiscing elit ut. Ac feugiat sed lectus vestibulum mattis ullamcorper. Tortor aliquam nulla facilisi cras. Odio ut sem nulla pharetra diam sit. Praesent tristique magna sit amet purus gravida quis blandit turpis[^1].
Elementum facilisis leo vel fringilla est ullamcorper eget nulla. Pellentesque diam volutpat commodo sed egestas egestas fringilla phasellus. Id leo in vitae turpis. Risus in hendrerit gravida rutrum. Fames ac turpis egestas integer eget aliquet. Fermentum iaculis eu non diam phasellus vestibulum lorem sed. Faucibus nisl tincidunt eget nullam.
[^1]: Reference
[/raw]
We have observed two examples and have identified the sections we intend to use; thus, we can proceed to the next step: converting our JSON content into markdown files.
For this process, you can use the Wp Posts To Markdown Files W Nodejs application. Instructions are defined within the README. Within a few minutes, your files will be organized into folders and ready for use, based on your article, category, tag, and any other fields you wish to include.
If your articles contain code, iframe, table, script, special characters, or other elements, you may need to adjust them separately. At this stage, you can perform interventions via the command line. For this purpose, you may also review the Regex rules. Below, I will provide you with a few topics that can be useful during the content workflow.
Helpful Tools
Now, let’s move on to the Grav usage process. You can consider the following tips regarding content creation, control, and site management.
Git-Sync Plugin
You can maintain the Posts, Plugins, Themes, Config, and Data sections within git environments, allowing you to manage your site from there.
Visual Studio Code - Markdown Extensions
You can manage your content using Visual Studio Code. For Markdown content, I recommend the following extensions: Prettier, Markdown All in One, Markdown Table Prettifier, Markdown Notes, and Markdown Footnote.
If you’d like to create content on your mobile phone or tablet, you can use Dropbox Paper, iA Writer, and for Git operations, Termux along with the Git package or the GitHub for mobile app. Your website is now accessible. Please share any questions you have in the comments.