1
), $args);
$id = 0;
$query = new WP_Query( $args );
while ( $query->have_posts() ) { $query->the_post();
$id = get_the_ID();
break;
}
wp_reset_postdata();
return $id;
}
}
// Return ID for the page with specified template
if (!function_exists('asia_garden_get_template_page_id')) {
function asia_garden_get_template_page_id($args=array()) {
$args = array_merge(array(
'template' => 'blog.php',
'post_type' => 'post'
), $args);
$q_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 1,
'meta_query' => array('relation' => 'AND')
);
if (!empty($args['template'])) {
$q_args['meta_query'][] = array(
'key' => '_wp_page_template',
'value' => $args['template'],
'compare' => '='
);
}
if (!empty($args['post_type'])) {
$q_args['meta_query'][] = array(
'key' => 'asia_garden_options_post_type',
'value' => $args['post_type'],
'compare' => '='
);
}
$q_args['meta_query'][] = array(
'key' => 'asia_garden_options_parent_cat',
'value' => 1,
'compare' => '<'
);
return asia_garden_get_post_id($q_args);
}
}
// Return link to the page with theme specific $post_type archive template page:
// page_template == blog.php and 'post_type'== $post_type and 'parent_cat' == 0
if ( !function_exists( 'asia_garden_get_template_page_link' ) ) {
//Handler of the add_filter('post_type_archive_link', 'asia_garden_get_template_page_link', 10, 2 );
function asia_garden_get_template_page_link($link='', $post_type='') {
if (!empty($post_type)) {
$id = asia_garden_get_template_page_id(array('post_type'=>$post_type));
if ($id > 0) $link = get_permalink($id);
}
return $link;
}
}
// Return current site protocol
if (!function_exists('asia_garden_get_protocol')) {
function asia_garden_get_protocol() {
return is_ssl() ? 'https' : 'http';
}
}
// Return internal page link - if is customize mode - full url else only hash part
if (!function_exists('asia_garden_get_hash_link')) {
function asia_garden_get_hash_link($hash) {
if (strpos($hash, 'http')!==0) {
if ($hash[0]!='#') $hash = '#'.$hash;
if (is_customize_preview()) {
$url = asia_garden_get_current_url();
if (($pos=strpos($url, '#'))!==false) $url = substr($url, 0, $pos);
$hash = $url . $hash;
}
}
return $hash;
}
}
// Return URL to the current page
if (!function_exists('asia_garden_get_current_url')) {
function asia_garden_get_current_url() {
global $wp;
// Attention! We don't need to process it with esc_url()
// since this url is being processed with esc_url() where it's used.
return home_url(add_query_arg(array(), $wp->request));
}
}
// Remove macros from the title
if ( !function_exists( 'asia_garden_wp_title' ) ) {
// Handler of the add_filter( 'wp_title', 'asia_garden_wp_title');
// Handler of the add_filter( 'wp_title_parts', 'asia_garden_wp_title');
// Handler of the add_filter( 'document_title_parts', 'asia_garden_wp_title');
function asia_garden_wp_title( $title ) {
if (is_array($title)) {
foreach ($title as $k=>$v)
$title[$k] = asia_garden_remove_macros($v);
} else
$title = asia_garden_remove_macros($title);
return $title;
}
}
// Return blog title
if (!function_exists('asia_garden_get_blog_title')) {
function asia_garden_get_blog_title() {
if (is_front_page()) {
$title = esc_html__( 'Home', 'asia-garden' );
} else if ( is_home() ) {
$title = esc_html__( 'All Posts', 'asia-garden' );
} else if ( is_author() ) {
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
// Translators: Add the author's name to the title
$title = sprintf(esc_html__('Author page: %s', 'asia-garden'), $curauth->display_name);
} else if ( is_404() ) {
$title = esc_html__('URL not found', 'asia-garden');
} else if ( is_search() ) {
// Translators: Add the author's name to the title
$title = sprintf( esc_html__( 'Search: %s', 'asia-garden' ), get_search_query() );
} else if ( is_day() ) {
// Translators: Add the queried date to the title
$title = sprintf( esc_html__( 'Daily Archives: %s', 'asia-garden' ), get_the_date() );
} else if ( is_month() ) {
// Translators: Add the queried month to the title
$title = sprintf( esc_html__( 'Monthly Archives: %s', 'asia-garden' ), get_the_date( 'F Y' ) );
} else if ( is_year() ) {
// Translators: Add the queried year to the title
$title = sprintf( esc_html__( 'Yearly Archives: %s', 'asia-garden' ), get_the_date( 'Y' ) );
} else if ( is_category() ) {
$title = single_cat_title( '', false );
} else if ( is_tag() ) {
// Translators: Add the tag's name to the title
$title = sprintf( esc_html__( 'Tag: %s', 'asia-garden' ), single_tag_title( '', false ) );
} else if ( is_tax() ) {
$title = single_term_title( '', false );
} else if ( is_attachment() ) {
// Translators: Add the attachment's name to the title
$title = sprintf( esc_html__( 'Attachment: %s', 'asia-garden' ), get_the_title());
} else if ( is_single() || is_page() ) {
$title = get_the_title();
} else {
$title = get_the_title(); //get_bloginfo('name', 'raw');
}
return apply_filters('asia_garden_filter_get_blog_title', $title);
}
}
// Comment form fields order
if ( !function_exists( 'asia_garden_comment_form_fields' ) ) {
// Handler of the add_filter('comment_form_fields', 'asia_garden_comment_form_fields');
function asia_garden_comment_form_fields($comment_fields) {
if (asia_garden_get_theme_setting('comment_after_name')) {
$keys = array_keys($comment_fields);
if ($keys[0]=='comment') $comment_fields['comment'] = array_shift($comment_fields);
}
return $comment_fields;
}
}
// Return nav menu html
if ( !function_exists( 'asia_garden_get_nav_menu' ) ) {
function asia_garden_get_nav_menu($location='', $menu = '', $depth=11, $custom_walker=false) {
static $list = array();
if (is_array($location)) { $loc = $location; $location = ''; extract($loc); }
$slug = $location.'_'.$menu;
if (empty($list[$slug])) {
$args = array(
'menu' => empty($menu) || $menu=='default' || asia_garden_is_inherit($menu) ? '' : $menu,
'container' => 'nav',
'container_class' => (!empty($location) ? esc_attr($location) : 'menu_main') . '_nav_area'
. (!empty($class) ? ' '.esc_attr($class) : ''),
'container_id' => '',
'items_wrap' => '
',
'menu_class' => 'sc_layouts_menu_nav ' . (!empty($location) ? esc_attr($location) : 'menu_main') . '_nav',
'menu_id' => (!empty($location) ? esc_attr($location) : 'menu_main'),
'echo' => false,
'fallback_cb' => '',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => $depth
);
if (!empty($location))
$args['theme_location'] = $location;
if ($custom_walker && class_exists('asia_garden_custom_menu_walker'))
$args['walker'] = new asia_garden_custom_menu_walker;
// Remove spaces between menu items
$list[$slug] = preg_replace(array("/>[\r\n\s]*[\r\n\s]*<\\/ul>/"),
array(">"),
wp_nav_menu(apply_filters('asia_garden_filter_get_nav_menu_args', $args))
);
// Add Structured Data Snippet
$list[$slug] = str_replace("