How to migrate Wordpress Metadata to Grav

I have managed to migrate from wordpress to Grav (test site so far which is not disclosed to the world yet).
permalinks, titles etc have come good.
However, i used Yoast SEO plugin with wordpress, which created meta tags like description, og:image, og:twitter, og:facebook etc…

How to migrate these metatags to grav ?
Most important is meta description. Others can be regenerated if social sharing plugins exist

@Turum, There is a handful of Grav plugins that can help you manage meta data.

Have a look at https://getgrav.org/downloads/plugins and search for ‘meta’ or ‘seo’.

However, I doubt if they can help converting Yoast’s meta though…

There are tools that allow you to export Yoast’s data into csv-files, which could be converted into yaml for each page. These tools do not come for free though…

1 Like

I could buy one of those as i have almost 900 posts with meta data.
But is there a way to import that csv to respective pages in grav.

I already used wordpress to grav migration plugin with CLI which imports xml files exported from wordpress.
If i have to individually create 900 yaml for each page then process of conversion becomes manual

Quite a good question, thank you for your reply.

To save you the expense of a yoast export plugin, I think you could get the data with an SQL query along these lines:

SELECT post_title, meta_value
FROM wp_posts
INNER JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
WHERE post_type IN ('page', 'post')
AND meta_key = '_yoast_wpseo_metadesc'

My last Q was : after exporting meta data of yoast, how to import them to each individual page in grav

if you are comfortable with writing scripts in perl, python or other language, you could do this probably relative easy by just scanning your pages folder for markdown files, then add the metadata yaml part via script.
probably the hardest part there will be to find the correct markdown file that corresponds to the mentioned post_title from the sql query.

I tried this, but as you said… the difficult part was finding the corresponding item.md for each page/post and add metadata to it.
If they were stored in a database, it would be somewhat easy to find them via ID numbers.
But they’re stored in .md files in corresponding folders with page title names.

After some struggle, understood that Grav/Markdown is not yet ready to handle such migration issues.
It is suitable only for new sites that start from scratch.
I’ll live with wordpress for some more time

@Turum, Please shoot my thinking where you foresee issues…

My thinking:

  • Getting slug/meta-data from Wordpress:
    • A SQL query in WordPress could be converted to { slug: meta-data[] }.
  • In Grav plugin:
    • Import data from WordPress
    • Subscribe to onPagesInitialized and get hold of the Pages object containing all page objects and their slugs, headers etc. No need to traverse through file system.
    • Loop through all pages in Pages object
      • Use $page->slug() to get meta-data from WP
      • Convert meta-data to Yaml
      • Inject meta-data into header of page object:
        $updatedHeader = // update header with meta-data
        $page->header($updatedHeader); // Set the header enriched with meta-data
        
      • Save page object to file:
        $page->save(); // Save page to file
        

And if this plugin works satisfactory, it might be a valuable candidate for Grav’s plugin repo…

I’m not good at coding…
All i could manage was : Translate the german post given in this link to english, export category wise .xml files from wordpress and then import them using linux CLI.
Every post succesfully migrated but meta data is stored by 3rd party plugins like Yoast/AIOSEO could not migrate.
I could get a database dump of those files too in .sql or .csv format but cannot import each of them to their respective item.md

Also my wordpress permalink structure is like : site.com/category1/post123.html

grav is asking me to create a /blog directory and move everything into it, then user @self.descdendants or @self.children in blod.md

but that will disrupt all permalinks.
Now they’ll look like site/blog/category/post123…
and i lose all search engine traffic, social share count, backlinks etc.

I used a quark theme skeleton but cant get latest 5-6 posts from all categories on my home page and everything is within /blog

@Turum,

but cant get latest 5-6 posts from all categories

  • You could try Collection::slice(0, 5) in Twig to get the latest 5 posts if sorted by date.

and everything is within /blog

  • When adding the following to the header of page /pages/blog/post123/item.md, the url will be http://site.com/category1/post123.html instead of e.g. http://site.com/blog/post123
    append_url_extension: '.html' <-- or add to config/system.yaml/pages
    routes:
      default: '/category1/post123'
    

As a side note:
Coincidentally, just got an email from Netlify announcing the upcoming online seminar Migrate a WordPress Site to the Jamstack on April 7th. If your site is near static anyway, it might be worth having a look when migrating to Grav appears to be too cumbersome.