Convert bookmarks.html file into WP posts

UPLOAD

The simplest way would be to use a form plugin. People like Contact Form 7, WPForms, other people like Gravity Forms. If you want the uploads to be from WordPress users only. You can hide the form in a password page, generate forms through shortcode on PHP conditional. etc.

You can create your own HTML form, using a shortcode or whatever, then just read the file instead of saving it to do your importing.

(Just some ideas, many more out there. Not much context of your project in post, so basically a blank slate of method you could choose).

IMPORT

So you have the .html export, either saved from a plugin and you can tap into it with a hook (sometimes like _after_post_submit), or it’s unsaved in PHP temp from a basic html form, and you just want to read and delete it. Doesn’t matter, the methods the same:

To find the links in the html file, you can use PHP DOMDocument Class, a library like php-selector, or just go vanilla and use basic fopen() and preg_match_all()

You’d have to create a method of identifying how the .html is built to know which browser its from, and thus what your DOM query, or regex pattern, will work.

Thereafter you’d have an array of links. Cycling through the array, check if a post of same link exists or not, then continue on and insert individually with wp_insert_post()


Please note that this is a broad answer for a broad question. Post some snippets of code you’ve tried, hurtles faced, etc. and they’ll be much more help available to you.

A great tip while starting any project is to write a comment list of what you want, then start filling in the code.

// create a upload form for users

// on form submit, save file

// open saved file

// find out which browser exported from

// ..etc.