How to add templates to the library

  • Create a folder named “tmea” in your theme and add your json files into that folder.
  • Add the following code to your functions file and edit the template names, tags, types and urls properly. You can define as many template as you want with the same structure.
add_action("rest_api_init",function(){
	
	add_filter( "TMEA_THEME_LIB", function( $theme_templates ){
		$theme_templates = [];
		// First Template
		$theme_templates[] = [
			'name'        => __("Template Name 1"),// Template name
			'tags'        => ['tag 1','tag 2','tag 3'], //tags [array]
			'type'        => ['theme','section'], // template types [array] : available template types: theme, section 				
			'imgUrl'      => 'https://source.unsplash.com/random/300x300', //thumbnail URL
			'largeImgUrl' => 'https://source.unsplash.com/random/600x1000.jpg', // full image url for lightbox
			'templateUrl' => get_template_directory_uri() . "/tmea/1.json" // template json url 
		];
		// Second Template
		$theme_templates[] = [
			'name'        => __("Template Name 2"),// Template name
			'tags'        => ['tag 1','tag 2','tag 3'], //tags [array] 
			'type'        => ['theme','section'], // template types [array] : available template types: theme, section 				
			'imgUrl'      => 'https://source.unsplash.com/random/300x300', //thumbnail URL
			'largeImgUrl' => 'https://source.unsplash.com/random/600x1000.jpg', // full image url for lightbox
			'templateUrl' => get_template_directory_uri() . "/tmea/2.json" // template json url 
		];
		return ($theme_templates);
	}, 1);
},5);
August 5, 2022