functns ph

<?php
/*
    Newspaper V6.3+ Child theme - Please do not use this child theme with older versions of Newspaper Theme

    What can be overwritten via the child theme:
     - everything from /parts folder
     - all the loops (loop.php loop-single-1.php) etc
	 - please read the child theme documentation: http://forum.tagdiv.com/the-child-theme-support-tutorial/


     - the rest of the theme has to be modified via the theme api:
       http://forum.tagdiv.com/the-theme-api/

 */




/*
    add the parent style + style.css from this folder
 */
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001);
function theme_enqueue_styles() {
    wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', TD_THEME_VERSION, 'all' );
    wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), TD_THEME_VERSION . 'c', 'all' );

}

/*
    Schema in wp text editor
 */
 
function tsm_get_extended_valid_elements() {
	$elements = array(
		'@' => array(
			'id',
			'class',
			'style',
			'title',
			'itemscope',
			'itemtype',
			'itemprop',
			'datetime',
			'rel'
		),
		'article', 'div', 'strong', 'h4', 'h3', 'h2', 'p', 'dl', 'dt', 'dd', 'ul', 'li', 'span',
		'a' => array(
			'href',
			'name',
			'target',
			'rev',
			'charset',
			'lang',
			'tabindex',
			'accesskey',
			'type',
			'class',
			'onfocus',
			'onblur'
		),
                'img' => array(
                        'src',
                        'alt',
                        'width',
                        'height'
                ),
		'meta' => array(
			'content'
		),
		'link' => array(
			'href'
		),
		'time' => array(
			'itemprop'
		)
	);

	return apply_filters( 'tsm_extended_valid_elements', $elements );
}

function tsm_tinymce_init( $settings )
{
	if( !empty( $settings['extended_valid_elements'] ) ) {
		$settings['extended_valid_elements'] .= ',';
	}

	$result = $settings['extended_valid_elements'];

	$elements = tsm_get_extended_valid_elements();

	foreach ( $elements as $key => $element ) {
		if ( is_array( $element ) && !empty( $key ) ) {
			$name = $key;
			$attributes = $element;
		} else {
			$name = $element;
			$attributes = array();
		}

		if ( !empty( $result ) ) {
			$result .= ',';
		}

		$result .= $name;

		if ( !empty( $attributes ) ) {
			$result .= '[' . implode('|', $attributes) . ']';
		}

	}

	$settings['extended_valid_elements'] = $result;
	if ( !isset($settings['valid_children'] ) ) {
		$settings['valid_children'] = '';
	}
	$settings['valid_children'] .= '+body[meta],+div[meta],+body[link],+div[link]';

	return $settings;
}

add_filter( 'tiny_mce_before_init', 'tsm_tinymce_init' );


/*****
Stop adding noopener tag automatically
*****/

add_filter('tiny_mce_before_init','tinymce_allow_unsafe_link_target');
function tinymce_allow_unsafe_link_target( $mceInit ) {
	$mceInit['allow_unsafe_link_target']=true;
	return $mceInit;
}


/*****
shortcode for flipkart Note: old class: sk-button sk-button--buy sk-button sk-button--flipkart sk-button--icon sk-button--icon-flipkart-black
*****/
add_shortcode('my_flipkart','my_flipkart_fctn');
function my_flipkart_fctn($atts) {
	$output = '';
	$atts = shortcode_atts(
		array(
			'row_num' => '0'
		), $atts
	);
	extract($atts);
	$table = CFS()->get('custom_field_table');

				if ($table) {
					foreach ($table as $row) {
						if ( $row['footer'] ) {
							foreach ( $row['footer'] as $tr ) {
								ob_start ();
								$row_num_less = --$row_num;
								
								$subrows = $tr['footer_row'];
								$specific_row = $subrows[$row_num_less];
								$sub_field_value = $specific_row['footer_td'];
								
								echo '<p style="text-align: center;">';
								echo '<a class="sk-button sk-button--buy sk-button sk-button--flipnew sk-button--icon sk-button--icon-flipkart-new" 
								title="View on Flipkart" rel="nofollow" 
								href="'.$sub_field_value.'" 
								target="_blank">Check Price</a>';
								echo '</p>';
								
								$grow_content = ob_get_contents ();
								ob_end_clean ();
							}
						}
					}
					
					$output .=  $grow_content;
				}
	return $output;
}

/*  
     REMOVE WP EMOJI
 */
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

/*  
Remove comments Website field
 */
add_filter('comment_form_default_fields', 'sk_remove_url');
 function sk_remove_url($fields)
 {
 if(isset($fields['url']))
 unset($fields['url']);
 return $fields;
 }
/*  
    Stop child theme css wpbeginner.com/wp-tutorials/how-wordpress-plugins-affect-your-sites-load-time/
 */
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'td-theme-child' );
wp_deregister_style( 'google-fonts-style' );
wp_deregister_style( 'pn-style' );
wp_deregister_style( 'pn-responsive' );
wp_deregister_style( 'pn-font-header' );
wp_deregister_style( 'pn-font-text' );
wp_deregister_style( 'mediaelementplayer-legacy' );
wp_deregister_style( 'wp-mediaelement' );
wp_deregister_style( 'wp-postratings' );
}

//Remove JQuery migrate
function remove_jquery_migrate($scripts)
{
    if (!is_admin() && isset($scripts->registered['jquery'])) {
        $script = $scripts->registered['jquery'];
        
        if ($script->deps) { // Check whether the script has any dependencies
            $script->deps = array_diff($script->deps, array(
                'jquery-migrate'
            ));
        }
    }
}

add_action('wp_default_scripts', 'remove_jquery_migrate');

/*  
Remove not needed scripts
 */
add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
 
function my_deregister_javascript() {
wp_deregister_script( 'wp-embed' );
wp_deregister_script( 'comment-reply' );
wp_deregister_script( 'wp-postratings' );

}

/*  
custom phone image size

function sk_newspaper_setup() {
	
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'phone-small-size', 90 );
}
add_action( 'after_setup_theme', 'sk_newspaper_setup' );

add_filter( 'image_size_names_choose', 'my_skcustom_sizes' );
function my_skcustom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'phone-small-size' => __( 'Phone Small Size' ),
    ) );
}  */

/*  
Activate shortcode function in Post Title
 */
add_filter( 'the_title', 'do_shortcode' );

/* shortcode: 2020  */
add_shortcode( 'year' , 'current_year' );
    function current_year() {
    $year = date("Y");
    return "$year";
}






/*  
GUitarutha function php begins
 */

/**
* Remove the slug from published post permalinks. Only affect our CPT though.
*/
function gp_remove_cpt_slug( $post_link, $post, $leavename ) {
 $custom_post_types = array( 'hindi-songs', 'english-songs' );
if ( ! in_array( $post->post_type, $custom_post_types ) || 'publish' != $post->post_status ) {
return $post_link;
}
 // This part is new for child posts
if( $post->post_parent ) {
$parent = get_post($post->post_parent);
$post_link = str_replace( '/' . $post->post_type . '/' . $parent->post_name . '/', '/', $post_link );
}
else {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}

return $post_link;
}
add_filter( 'post_type_link', 'gp_remove_cpt_slug', 10, 3 );



/**
* Have WordPress match postname to any of our public post types (page, post, race)
* All of our public post types can have /post-name/ as the slug, so they better be unique across all posts
* By default, core only accounts for posts and pages where the slug is /post-name/
*/
function gp_parse_request_trick( $query ) {
// Only noop the main query
if ( ! $query->is_main_query() )
return;
// Only noop our very specific rewrite rule match
if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
return;
}
// 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
if ( ! empty( $query->query['name'] ) ) {
$query->set( 'post_type', array( 'post', 'page', 'chords', 'tabs', 'hindi-songs', 'english-songs' ) );
}
}
add_action( 'pre_get_posts', 'gp_parse_request_trick' );


/*********************************************************************
Advanced use of attachments in WordPress
Functions for theme to display attachments in cusotm templates
*******************************************************************/

// add attachments to the main query using parse_query
function wptutsplus_add_attachments_to_tax_query() {

    global $wp_query;

    // When inside a custom taxonomy archive include attachments
    if ( is_tax( array( 'hindi-chords', 'chords-bundle', 'bass', 'fret' ) ) ) {
        $wp_query->query_vars['post_type'] =  array( 'attachment' );
		$wp_query->query_vars['post_mime_type'] =  array( 'image', 'audio' );
		
        $wp_query->query_vars['post_status'] =  array( null );
		
        return $wp_query;
    }

}
add_action('parse_query', 'wptutsplus_add_attachments_to_tax_query');

/*********************************************************************
shortcode for related tabs and chords HINDI
*******************************************************************/
add_shortcode('related_hindi_tab_chord','related_hindi_tab_chord_fctn');
function related_hindi_tab_chord_fctn() {
	$output = '';
	$guitarvalues = CFS()->get('related_hindi_guitar_tab_or_chord');
				if ($guitarvalues) {
					$output .= '<ul>';
					foreach ($guitarvalues as $post_id) {
						$the_post = get_post( $post_id );
	
						$output .= '<li><a href="'.get_permalink($post_id).'">'.$the_post->post_title.'</a></li>';	
					}		
					$output .= '</ul>';
				}
	return $output;
}

/*********************************************************************
shortcode for related tabs and chords English
*******************************************************************/
add_shortcode('related_english_tab_chord','related_english_tab_chord_fctn');
function related_english_tab_chord_fctn() {
	$output = '';
	$guitarvalues = CFS()->get('related_eng_guitar_tab_or_chord');
				if ($guitarvalues) {
					$output .= '<ul>';
					foreach ($guitarvalues as $post_id) {
						$the_post = get_post( $post_id );
	
						$output .= '<li><a href="'.get_permalink($post_id).'">'.$the_post->post_title.'</a></li>';	
					}		
					$output .= '</ul>';
				}
	return $output;
}

/*********************************************************************
shortcode for tuning
*******************************************************************/

add_shortcode('guitar_tuning','guitar_tuning_fctn');
function guitar_tuning_fctn() {
			$xtra_output = '';
			$terms = get_the_terms( $post->ID, 'tuning' );
			$myb4txt = "Tuning: ";
			
	        if ( is_wp_error( $terms ) )
	                return $terms;
	
	        if ( empty( $terms ) )
	                return false;

			$draught_links = array();

			foreach ( $terms as $term ) {
			$draught_links[] = $term->name;
			}

			$xtra_output .= join( ", ", $draught_links );
		
	 return '<strong> '.$myb4txt.' </strong> '. $xtra_output.'<br>';
}




/*********************************************************************
shortcode for scales
*******************************************************************/

add_shortcode('guitar_scale','guitar_scale_fctn');
function guitar_scale_fctn() {
			$xtra_output = '';
			$terms = get_the_terms( $post->ID, 'scales' );
			$myb4txt = "Scale: ";
		
	        if ( is_wp_error( $terms ) )
	                return $terms;
	
	        if ( empty( $terms ) )
	                return false;

			$draught_links = array();

			foreach ( $terms as $term ) {
			$draught_links[] = $term->name;
			}

			$xtra_output .= join( ", ", $draught_links );

	 return '<strong> '.$myb4txt.' </strong> '. $xtra_output.'<br>';
}

/*********************************************************************
shortcode for capo
*******************************************************************/

add_shortcode('guitar_capo','guitar_capo_fctn');
function guitar_capo_fctn() {
			$xtra_output = '';
			$terms = get_the_terms( $post->ID, 'capo' );
			$myb4txt = "Capo: ";
		
	        if ( is_wp_error( $terms ) )
	                return $terms;
	
	        if ( empty( $terms ) )
	                return false;

			$draught_links = array();

			foreach ( $terms as $term ) {
			$draught_links[] = $term->name;
			}

			$xtra_output .= join( ", ", $draught_links );

	 return '<strong> '.$myb4txt.' </strong> '. $xtra_output.'<br>';
}

/*********************************************************************
shortcode for chords
*******************************************************************/

add_shortcode('guitar_chords','guitar_chords_fctn');
function guitar_chords_fctn() {
			$xtra_output = '';
			$terms = get_the_terms( $post->ID, 'hindi-chords' );
			$myb4txt = "CHORDS: ";
		
	        if ( is_wp_error( $terms ) )
	                return $terms;
	
	        if ( empty( $terms ) )
	                return false;

			$draught_links = array();

			foreach ( $terms as $term ) {
			$draught_links[] = $term->name;
			}

			$xtra_output .= join( ", ", $draught_links );
		
	 return '<strong> '.$myb4txt.' </strong> '. $xtra_output.'<br>';
}

/*********************************************************************
shortcode for collapsomydiv Hindi
*******************************************************************/
add_shortcode('collapso_short','collapso_short_fctn');
function collapso_short_fctn() {
	$output = '';
	ob_start ();
	$rows = CFS()->get('hindi_chords_details');
				if ($rows) {
					foreach ($rows as $row) {
						$chordioimgwidth = "260";
						$audio_class = "audio-playerqq";
						$audio_type = "audio/mpeg";
						echo '<div class="mydivchordio">';
						echo '<img src="' . $row['hindi_chord_image'] . '" width="'.$chordioimgwidth.'" alt="' . $row['hindi_image_alt_tag'] . '" />';
						echo do_shortcode( '  . '"] ' );
						echo '</div>';
					}

					$row_content = ob_get_contents ();
					ob_end_clean ();
					$output .=  '<div class="collapsomydiv" id="collapsomyid">';
					$output .=  do_shortcode( '"▼"h2">"▲"h2">
' .$row_content. '
' ); $output .= '</div>'; $output .= '<div class="clear"></div>'; } return $output; } /********************************************************************* shortcode for collapsomydiv English *******************************************************************/ add_shortcode('collapso_short_eng','collapso_short_eng_fctn'); function collapso_short_eng_fctn() { $output = ''; ob_start (); $rows = CFS()->get('eng_chords_details'); if ($rows) { foreach ($rows as $row) { $chordioimgwidth = "260"; $audio_class = "audio-playerqq"; $audio_type = "audio/mpeg"; echo '<div class="mydivchordio">'; echo '<img src="' . $row['eng_chord_image'] . '" width="'.$chordioimgwidth.'" alt="' . $row['eng_image_alt_tag'] . '" />'; echo do_shortcode( ' . '"] ' ); echo '</div>'; } $row_content = ob_get_contents (); ob_end_clean (); $output .= '<div class="collapsomydiv" id="collapsomyid">'; $output .= do_shortcode( '"▼"h2">"▲"h2">
' .$row_content. '
' ); $output .= '</div>'; $output .= '<div class="clear"></div>'; } return $output; } /********************************************************************* shortcode for more songs from movie *******************************************************************/ add_shortcode('more_songs_movie','more_songs_movie_fctn'); function more_songs_movie_fctn() { $xtra_output = ''; $terms = get_the_terms( $post->ID, 'movies' ); $myb4txt = "CHORDS: "; if ( is_wp_error( $terms ) ) return $terms; if ( empty( $terms ) ) return false; $links = array(); foreach ( $terms as $term ) { $link = get_term_link( $term, 'movies' ); if ( is_wp_error( $link ) ) { return $link; } $links[] = '<a class="my-more-songs-link" target="_blank" href="' . esc_url( $link ) . '" rel="tag"><div class="more-songs-div-1"><div class="left-triangle"></div><div class="more-songs-center-text">More Guitar Lessons From ' . $term->name . ' <span class="ctaText">►</span></div><div class="right-triangle-main"><div class="right-triangle"></div></div></div></a>'; } $xtra_output .= join( ", ", $links ); return $xtra_output; } /********************************************************************* shortcode for collapsomydiv youtube video *******************************************************************/ add_shortcode('collapso_short_contributor_video','collapso_short_contributor_video_fctn'); function collapso_short_contributor_video_fctn() { $output = ''; $grows = CFS()->get('youtube_video_id'); $dmrows = CFS()->get('dailymotion_embed_code'); if (!empty($grows)) { ob_start (); $thumb_id = get_post_thumbnail_id(); $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); $thumb_url = $thumb_url_array[0]; $myb4txt = "Continue reading, Chords and Lyrics are given below."; $myb4txt2 = "Sharing is Artistic » "; $collapso_utube_heading = CFS()->get('youtube_video_heading'); $utube_video_id = CFS()->get('youtube_video_id'); $utube_username = CFS()->get('youtube_username'); $utube_shown_username = CFS()->get('shown_youtube_username'); $more_songs_4m_movie = do_shortcode( '' ); echo '<div class="" id="'.$utube_video_id.'" itemprop="video" itemscope itemtype="http://schema.org/VideoObject">'; echo '<div class="targ-video">'; echo '<meta itemprop="name" content="'.$myb4txt2.'">'; echo '<meta itemprop="duration" content="'.$myb4txt2.'" />'; echo '<meta itemprop="thumbnailURL" content="'.$thumb_url.'">'; echo '<div class="youtube-player" data-id="'.$utube_video_id.'"></div>'; echo '<span style="color: #444; float:left; display: inline-block; margin: 10px 20px 0 0;">Credit: ' .$utube_shown_username.' </span>'; echo '</div>'; echo '<div class="clear"></div>'; echo '<strong style="color: #444;"> '.$myb4txt.' </strong> '; echo '<div itemprop="description" class="chapter-timeline">'; echo CFS()->get('youtube_timeline'); echo '</div>'; echo '</div>'; $grow_content = ob_get_contents (); ob_end_clean (); $output .= '<div class="collapsomydiv" id="collapsomyid">'; $output .= do_shortcode( '"▼"h2">"▲"h2">
' .$grow_content. '
' ); $output .= '</div>'; $output .= '<div class="clear"></div>'; $output .= $more_songs_4m_movie; $output .= '<div class="clear"></div>'; } elseif (!empty($dmrows)) { ob_start (); $myb4txt = "Continue reading, Chords and Lyrics are given below."; $myb4txt2 = "Sharing is Artistic » "; $dm_username = CFS()->get('dailymotion_username'); $more_songs_4m_movie = do_shortcode( '' ); echo '<div class="targ-video">'; echo CFS()->get('dailymotion_embed_code'); echo '<span style="color: #444; float:left; display: inline-block; margin: 10px 20px 0 0;">Credit: ' .$dm_username.' </span>'; echo '</div>'; echo '<div class="clear"></div>'; echo '<strong style="color: #444;"> '.$myb4txt.' </strong> '; echo '<div class="chapter-timeline">'; echo CFS()->get('dailymotion_timeline'); echo '</div>'; $dmrow_content = ob_get_contents (); ob_end_clean (); $output .= '<div class="collapsomydiv" id="collapsomyid">'; $output .= do_shortcode( '"▼"h2">"▲"h2">
' .$dmrow_content. '
' ); $output .= '</div>'; $output .= '<div class="clear"></div>'; $output .= $more_songs_4m_movie; $output .= '<div class="clear"></div>'; } return $output; } /********************************************************************* shortcode for contributor later when videos are uploaded *******************************************************************/ add_shortcode('guitar_contributor','guitar_contributor_fctn'); function guitar_contributor_fctn() { $xtra_output = ""; $contributor_list = get_the_term_list( $post->ID, 'contributor', '<strong>Contributor:</strong> ', ', ', '' ); if ( '' != $contributor_list ) { $xtra_output .= "$contributor_list<br />\n"; } if ( '' != $xtra_output ) { return $xtra_output; } } /********************************************************************* shortcode for instructor later when videos are uploaded *******************************************************************/ add_shortcode('guitar_instructor','guitar_instructor_fctn'); function guitar_instructor_fctn() { $xtra_output = ''; $terms = get_the_terms( $post->ID, 'instructor' ); $myb4txt = "Instructor: "; if ( is_wp_error( $terms ) ) return $terms; if ( empty( $terms ) ) return false; $draught_links = array(); foreach ( $terms as $term ) { $draught_links[] = $term->name; } $xtra_output .= join( ", ", $draught_links ); return '<strong> '.$myb4txt.' </strong> '. $xtra_output.'<br>'; } /********************************************************************* wp-page navi and authorphp *******************************************************************/ function custom_author_archive( &$query ) { if ($query->is_author) $query->set( 'post_type', array( 'hindi-songs', 'english-songs' ) ); } add_action( 'pre_get_posts', 'custom_author_archive' ); /********************************************************************* copyright footer info *******************************************************************/ function wpb_copyright() { global $wpdb; $copyright_dates = $wpdb->get_results(" SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = 'publish' "); $output = ''; if($copyright_dates) { $copyright = "&copy; " . $copyright_dates[0]->firstdate; if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) { $copyright .= '-' . $copyright_dates[0]->lastdate; } $output = $copyright; } return $output; } add_shortcode('copyright','wpb_copyright'); add_filter('widget_text', 'do_shortcode'); /************************************************** count and display common terms by relatd posts by taxo ***************************************************/ add_filter( 'related_posts_by_taxonomy', 'rpbt_add_common_terms', 10, 4 ); function rpbt_add_common_terms( $related, $post_id, $taxonomies, $args ) { if ( !( isset( $args['related_terms'] ) && $args['related_terms'] ) ) { return $related; } // get the terms (objects) used to calculate the related posts $related_terms = get_terms( array( 'taxonomy' => 'hindi-chords', 'include' => $args['related_terms'], ) ); // get the term names $names = wp_list_pluck( $related_terms, 'name', 'term_id' ); foreach ( $related as $key => $post ) { // Get the terms from the related post. $terms = wp_get_object_terms( $post->ID, 'hindi-chords', array( 'fields' => 'ids' ) ); if ( has_term( 'chords', 'hs-types' ) ) { // Get common terms from the related post as array keys. $in_common = array_flip( array_intersect( $terms, $args['related_terms'] ) ); // Get the term names. $in_common = array_intersect_key( $names, $in_common ); $title = count( $in_common ) . '/' . count( $terms ); $title .= ' Chords Common – ' . implode( ', ', $in_common ); $related[$key]->in_common = $title; } } return $related; } /************************************************** display common terms with thumbnails by relatd posts by taxo ***************************************************/ add_filter( 'related_posts_by_taxonomy_caption', 'rpbt_add_common_terms_gallery_caption', 10, 2 ); function rpbt_add_common_terms_gallery_caption( $caption, $post ){ $caption = '<a href=' . get_permalink( $post->ID ) . '>' . $caption . '</a>'; $caption .= isset($post->in_common) ? '<span class="metainfo-spans">' . $post->in_common : '</span>' ; return $caption; } /************************************************** your own fallback image for related post by taxonomy ***************************************************/ // Adds the 'Post Images' format to the widget // after the plugin's defaults are set (priority 11). add_action( 'wp_loaded', 'rpbt_add_post_images_format_widget', 11 ); function rpbt_add_post_images_format_widget() { if ( !class_exists( 'Related_Posts_By_Taxonomy_Defaults' ) ) { return; } $defaults = Related_Posts_By_Taxonomy_Defaults::get_instance(); // Add the new format. $defaults->formats['images'] = __( 'Post Images' ); } // Sets the format to thumbnails if the Post Images format is used. // Adds filters to remove the sql used to only find posts with post thumbnails. add_filter( 'related_posts_by_taxonomy_shortcode_atts', 'rpbt_post_images_format' ); add_filter( 'related_posts_by_taxonomy_widget_args', 'rpbt_post_images_format' ); function rpbt_post_images_format( $args ) { // Check if the new images format is used. if ( 'images' === $args['format'] ) { // Set format to thumbnails if Post Images format is used. $args['format'] = 'thumbnails'; // Removes the sql to search for posts with post thumbnails only. add_filter( 'get_meta_sql', '__return_empty_string', 23 ); // Removes the filter after related posts are retrieved. add_filter( 'related_posts_by_taxonomy', 'rpbt_remove_meta_sql_filter' ); // Removes the filter if no related posts were found. add_action( 'related_posts_by_taxonomy_after_display', 'rpbt_remove_meta_sql_filter' ); } return $args; } // Remove the filter function rpbt_remove_meta_sql_filter( $results ) { remove_filter( 'get_meta_sql', '__return_empty_string', 23 ); return $results; } // Use a fallback image if a post has no post thumbnail. add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'rpbt_related_post_fallback_image', 10, 4 ); function rpbt_related_post_fallback_image( $image, $attr, $related, $args ) { if ( !empty( $image ) ) { // Post thumbnail found. return $image; } $image_args = array( 'numberposts' => 1, 'order' => 'ASC', 'post_mime_type' => 'image', 'post_parent' => $related->ID, 'post_status' => null, 'post_type' => 'attachment', ); $attachments = get_children( $image_args ); if ( !empty( $attachments ) ) { // Post attachment image found. $attachments = array_values( $attachments ); $attachment_id = (int) $attachments[0]->ID; // Use the first attachment image. $image = wp_get_attachment_image( $attachment_id , $args['size'], false, $attr['describedby'] ); } else { /** * Use your own fallback image here. * * Example of an image uploaded with the media editor. * Change the attachment ID (123) below to your uploaded fallback image ID. * And remove the two foreward slashes at the beginning. */ $image = wp_get_attachment_image( 2448, $args['size'], false, $attr['describedby'] ); } $image = $image ? "<a href='{$attr['permalink']}' title='{$attr['title_attr']}'>{$image}</a>" : ''; return $image; } /** Different menu for guitar pages */ // Conditionally change menus add_filter( 'wp_nav_menu_args', 'ani_wp_nav_menu_args' ); function ani_wp_nav_menu_args( $args = '' ) { // change the menu in the Header menu position if( $args['theme_location'] == 'header-menu' && ( is_singular('hindi-songs') || is_singular('english-songs') || is_page('3295') || is_page_template( 'guitar-sngs-template.php' ) || is_page_template( 'guitar-easy-sngs-template.php' ) || is_page_template( 'guitar-latest-sngs-template.php' ) || is_author() || is_post_type_archive('hindi-songs') || is_post_type_archive('english-songs') || is_tax( 'hs-types', 'chords' ) || is_tax( 'hs-types', 'tabs' ) || is_tax( 'es-types', 'chords' ) || is_tax( 'es-types', 'tabs' ) || is_tax( 'hs-difficulty' ) || is_tax( 'es-difficulty' ) || is_tax( 'hs-category' ) || is_tax( 'es-category' ) || is_tax( 'artists' ) || is_tax( 'singers' ) || is_tax( 'lyricists' ) || is_tax( 'movies' ) || is_tax( 'albums' ) || is_tax( 'music-directors' ) )) { $args['menu'] = '539'; // 539 is the ID of the menu we want to use here } return $args; } /** Guitarutha function ends */