Snippets

Pavel Petrov How to show tags under post content in WordPress

Created by Pavel Petrov
<?php
//...
//functions.php
/* Adding Post Tags */
add_action( 'wp_enqueue_scripts', function(){
    wp_enqueue_style( 'PostTags-CSS', get_stylesheet_directory_uri().'/css/tags.css' );
});
add_filter('the_content', function($content) {
    $postID = get_the_ID();
    $tags = function() use($postID){
        $tagsList = wp_get_post_tags($postID);
        $html = "<br><ul class='post-tags'>";
        foreach($tagsList as $tag)
        {
            $html .= '<li><a href="#">'.$tag->name.'</a></li>';
        }
        $html .= "</ul>";
        return $html;
    };
    return $content.$tags();
});
.post-tags{
	margin:0;
	padding:0;
	list-style:none !important;
}
.post-tags li, .post-tags a{
	float:left;
	height:24px;
	line-height:24px;
	position:relative;
	font-size:11px;
}
.post-tags a{
	margin-left:20px;
	padding:0 10px 0 12px;
	background:#0089e0;
	color:#fff;
	text-decoration:none;
	-moz-border-radius-bottomright:4px;
	-webkit-border-bottom-right-radius:4px;	
	border-bottom-right-radius:4px;
	-moz-border-radius-topright:4px;
	-webkit-border-top-right-radius:4px;	
	border-top-right-radius:4px;	
}
.post-tags a:before{
	content:"";
	float:left;
	position:absolute;
	top:0;
	left:-12px;
	width:0;
	height:0;
	border-color:transparent #0089e0 transparent transparent;
	border-style:solid;
	border-width:12px 12px 12px 0;		
}
.post-tags a:after{
	content:"";
	position:absolute;
	top:10px;
	left:0;
	float:left;
	width:4px;
	height:4px;
	-moz-border-radius:2px;
	-webkit-border-radius:2px;
	border-radius:2px;
	background:#fff;
	-moz-box-shadow:-1px -1px 2px #004977;
	-webkit-box-shadow:-1px -1px 2px #004977;
	box-shadow:-1px -1px 2px #004977;
}
.post-tags a:hover{background:#555;}	
.post-tags a:hover:before{border-color:transparent #555 transparent transparent;}

Comments (0)