WordPress Snippets


<?php
/* Tag list */
the_tags(' ', ' ', ' ');
echo get_the_tag_list("<ul class=\"list-unstyled text-center\"><li>", "</li><li>", "</li></ul>");

/* Get All tags */
$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
	$tag_link = get_tag_link( $tag->term_id );
			
	$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
	$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;


/* Post thumbnail */
if(has_post_thumbnail()){
	the_post_thumbnail('large', array('class' => 'img-fluid'));   
}

/* Comments */
if(comments_open()): ?>
	<div class="col-md-10 offset-md-1">
		<?php comments_template();?>
	</div>
<?php endif;


/* Post pagination */
the_posts_pagination(array(
	"screen_reader_text" => ' '
	)
);

/* template file included */
get_template_part('');


/* php file or lib included */
get_theme_file_path('');


/* post navigation */
next_post_link();
echo "<br>";
previous_post_link();


/* password protected post */
function alpha_protected_post($excerpt){
	if (! post_password_required()) {
		return $excerpt;
	}else{
		echo get_the_password_form();
	}
}

add_filter('the_excerpt', 'alpha_protected_post');


/* css added in header */
function launcher_style(){
	if (is_page()) {
		$thumb_img = get_the_post_thumbnail_url( null, 'large' );
		?>
		<style>
			.home-side{
				background-image: url(<?php echo $thumb_img;?>);
			}
		</style>
		<?php
	}
}

add_action( 'wp_head', 'launcher_style', 11);


/* custom meta field data retrieve */
$placeholder = get_post_meta( get_the_ID(), 'placeholder', true );


/* post format */
$alpha_format = get_post_format();


/* author info */
get_the_author_meta();


/* author image */
echo get_avatar( get_the_author_meta( 'id') );


/* body class remove or add */
function alpha_body_class($classes){
	unset($classes[array_search('wp-custom-logo', $classes)]);
	$classes[] = "newclass_add";
	return $classes;
}

add_filter( 'body_class','alpha_body_class');


/* post class remove or add */
function alpha_post_class($classes){
	unset($classes[array_search('tag-blog', $classes)]);	
	return $classes;
}

add_filter( 'post_class','alpha_post_class');


/* image srcset remove */
function alpha_image_srcset(){
	return null;
}
add_filter( 'wp_calculate_image_srcset', 'alpha_image_srcset' );


/* If you want to override a function into the child theme, just put in a check */
if(!function_exists('alpha_date')) {
	function alpha_date(){
		echo date("d/m/y");
	}
}

?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s