", "", ), array( "img", ""; $returnData = preg_replace($re, $subst, $returnData); break; } return $returnData; } } //Facility to create child theme For AMP add_filter( 'amp_post_template_file', 'ampforwp_child_custom_header_file', 20, 3 ); add_filter( 'amp_post_template_file', 'ampforwp_child_designing_custom_template', 20, 3 ); add_filter( 'amp_post_template_file', 'ampforwp_child_custom_footer_file', 20, 3 ); function ampforwp_theme_template_directry(){ return get_template_directory() . '/amp/'; } // Custom Header function ampforwp_child_custom_header_file( $file, $type, $post ) { $currentFile = $file; if ( 'header' === $type ) { $file = ampforwp_theme_template_directry() . '/header.php'; } if ( 'header-bar' === $type ) { $file = ampforwp_theme_template_directry() . '/header-bar.php'; } if(!file_exists($file)){ $file = $currentFile; } return $file; } // Custom Template Files function ampforwp_child_designing_custom_template( $file, $type, $post ) { global $redux_builder_amp; $currentFile = $file; $filePath = ampforwp_theme_template_directry(); // Single file if ( is_single() ) { if( 'single' === $type && ! ('product' === $post->post_type) ) { $file = $filePath . '/single.php'; } } if ( is_page() ) { if( 'single' === $type && ! ('product' === $post->post_type) ) { $file = $filePath . '/page.php'; } } // Loop Template if ( 'loop' === $type ) { $file = $filePath . '/loop.php'; } // Archive if ( is_archive() ) { if ( 'single' === $type ) { $file = $filePath . '/archive.php'; } } $ampforwp_custom_post_page = ampforwp_custom_post_page(); // Homepage if ( is_home() ) { if ( 'single' === $type ) { $file = $filePath . '/index.php'; if ( $redux_builder_amp['amp-frontpage-select-option'] == 1 ) { $file = $filePath . '/page.php'; } if ( ampforwp_is_blog() ) { $file = $filePath . '/index.php'; } } } // is_search if ( is_search() ) { if ( 'single' === $type ) { $file = $filePath . '/search.php'; } } //For template pages switch ( true ) { case (is_tax()): $term = get_queried_object(); $templates = array(); if ( ! empty( $term->slug ) ) { $taxonomy = $term->taxonomy; $slug_decoded = urldecode( $term->slug ); if ( $slug_decoded !== $term->slug ) { $templates[] = $filePath . "/taxonomy-$taxonomy-{$slug_decoded}.php"; } $templates[] = $filePath . "/taxonomy-$taxonomy-{$term->slug}.php"; $templates[] = $filePath . "/taxonomy-$taxonomy.php"; } $templates[] = $filePath . "/taxonomy.php"; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; case (is_category()): $category = get_queried_object(); $templates = array(); if ( ! empty( $category->slug ) ) { $slug_decoded = urldecode( $category->slug ); if ( $slug_decoded !== $category->slug ) { $templates[] = $filePath . "/category-{$slug_decoded}.php"; } $templates[] = $filePath . "/category-{$category->slug}.php"; $templates[] = $filePath . "/category-{$category->term_id}.php"; } $templates[] = $filePath . '/category.php'; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; case (is_tag()): $tag = get_queried_object(); $templates = array(); if ( ! empty( $tag->slug ) ) { $slug_decoded = urldecode( $tag->slug ); if ( $slug_decoded !== $tag->slug ) { $templates[] = $filePath . "/tag-{$slug_decoded}.php"; } $templates[] = $filePath . "/tag-{$tag->slug}.php"; $templates[] = $filePath . "/tag-{$tag->term_id}.php"; } $templates[] = $filePath . '/tag.php'; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; case (is_archive()): $post_types = array_filter( (array) get_query_var( 'post_type' ) ); $templates = array(); if ( count( $post_types ) == 1 ) { $post_type = reset( $post_types ); $templates[] = $filePath . "/archive-{$post_type}.php"; } $templates[] = $filePath . '/archive.php'; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; case (is_post_type_archive()): $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) $post_type = reset( $post_type ); $obj = get_post_type_object( $post_type ); if ( ! ($obj instanceof WP_Post_Type) || ! $obj->has_archive ) { //return ''; break; } $post_types = array_filter( (array) get_query_var( 'post_type' ) ); $templates = array(); if ( count( $post_types ) == 1 ) { $post_type = reset( $post_types ); $templates[] = $filePath . "/archive-{$post_type}.php"; } $templates[] = $filePath . '/archive.php'; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; case is_single(): $object = get_queried_object(); $templates = array(); if ( ! empty( $object->post_type ) ) { $template = get_page_template_slug( $object ); if ( $template && 0 === validate_file( $template ) ) { $templates[] = $template; } $name_decoded = urldecode( $object->post_name ); if ( $name_decoded !== $object->post_name ) { $templates[] = $filePath . "/single-{$object->post_type}-{$name_decoded}.php"; } $templates[] = $filePath . "/single-{$object->post_type}-{$object->post_name}.php"; $templates[] = $filePath . "/single-{$object->post_type}.php"; } $templates[] = $filePath . "/single.php"; foreach ( $templates as $key => $value ) { if ( 'single' === $type && file_exists($value) ) { $file = $value; break; } } break; } if(!file_exists($file)){ $file = $currentFile; } return $file; } // Custom Footer function ampforwp_child_custom_footer_file( $file, $type, $post ) { $currentFile = $file; if ( 'footer' === $type ) { $file = ampforwp_theme_template_directry() . '/footer.php'; } if(!file_exists($file)){ $file = $currentFile; } return $file; }