So, are you looking for a JSON importer for Elementor? If so, why not use their native importer? See here:
However, if you would rather have an option in a menu, try this small plugin. It adds an importer under Tools > Import
, called Elementor JSON Importer, that you can use to import JSON files (it technically also handles .zip files). With it, you can upload a JSON file and it generates an Elementor template from it. It saves the uploaded files in the wp-content/uploads
folder.
<?php
/**
* Elementor JSON Importer
*
* Plugin Name: Elementor Importer
* Plugin URI: https://example.com
* Description: Imports local JSON data and creates an Elementor post.
* Version: 0.1.0
* Author: Your Name Here
* Author URI: https://example.com
* Text Domain: elementor-json-importer
*/
if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
return;
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
// Require Elementor API
require_once plugin_dir_path( __DIR__ ) . 'elementor/includes/template-library/sources/base.php';
require_once plugin_dir_path( __DIR__ ) . 'elementor/includes/template-library/sources/local.php';
// Make sure the importer class exists and is available.
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) {
require_once $class_wp_importer;
}
}
/**
* Elementor JSON Importer
*
* Will process JSON data for importing Elementor posts into WordPress.
*
* @since 0.1.0
*/
if ( class_exists( 'WP_Importer' ) ) {
class Elementor_JSON_Importer extends WP_Importer {
// Constructor
public function __construct() {
// Nothing.
}
// Executes on import dispatch.
public function dispatch() {
if ( empty( $_GET['step'] ) ) {
$step = 0;
} else {
$step = (int) $_GET['step'];
}
$this->header();
switch ($step) {
case 0:
$this->greet();
break;
case 1:
check_admin_referer( 'import-upload' );
$result = $this->import();
if ( is_wp_error( $result ) ) {
echo $result->get_error_message();
}
break;
}
$this->footer();
}
// Echoes page footer.
protected function footer() {
echo '</div>';
}
// Echoes greeting.
protected function greet() {
echo '<div class="narrow">';
echo '<p>'.__( 'This importer allows you to extract posts from an Elementor JSON file into your WordPress site. Pick a JSON file to upload and click Import.', 'elementor-json-importer' ).'</p>';
wp_import_upload_form( 'admin.php?import=elementor-json&step=1' );
echo '</div>';
}
// Echoes page header.
protected function header() {
echo '<div class="wrap">';
screen_icon();
echo '<h2>'.__( 'Import JSON', 'elementor-json-importer-importer' ).'</h2>';
}
// Performs the actual import by using methods of the Elementor API.
protected function import() {
$error = new WP_Error();
$file = wp_import_handle_upload();
if ( isset( $file['error'] ) ) {
$error->add( 'upload-error', $file['error'] );
return $error;
}
$source_local = new Elementor\TemplateLibrary\Source_Local();
if ( ! method_exists( $source_local, 'import_template' ) ) {
$error->add( 'elementor-api-error', __( 'Elementor API unavailable.', 'elementor-json-importer' ) );
return $error;
}
try {
$result = $source_local->import_template( basename( $file['file'] ), $file['file'] );
} catch ( Exception $e ) {
$error->add( 'elementor-import-error', __( 'Elementor import has failed.', 'elementor-json-importer' ) );
return $error;
} finally {
wp_import_cleanup( $file['id'] );
}
echo '<h3>';
printf( __( 'All done. <a href="https://wordpress.stackexchange.com/questions/351334/%s">View template</a>', 'rss-importer' ), esc_url( $result[0]['url'] ) );
echo '</h3>';
}
}
// Create a new instance of the importer class.
$elementor_json_importer = new Elementor_JSON_Importer();
// Attempt to register importer.
$error = register_importer(
'elementor-json',
__( 'Elementor JSON Importer', 'elementor-json-importer' ),
__( 'Import posts from an Elementor JSON file.', 'elementor-json-importer' ),
array ( $elementor_json_importer, 'dispatch' )
);
if ( is_wp_error( $error ) ) {
error_log( $error->get_error_message() );
}
} // class_exists( 'WP_Importer' )
function elementor_json_importer_init() {
load_plugin_textdomain( 'elementor-json-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'elementor_json_importer_init' );
It depends heavily on the Elementor plugin, though, so make sure to check if it works each time the Elementor plugin receives an update.