• Resolved anas33chaudhary

    (@anas33chaudhary)


    I am using a php snippets

    $tags = get_tags();
    
     foreach ($tags as $tag)
     {
       if($tag->name=='fill') continue;// do this for every tag you want gone
       echo $tag->name.'  ';  
     }

    and displaying it at specific location using shortcode. I want to know how can I change its styles using css or any other method?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @anas33chaudhary,

    In order to style the output of that code you will need to wrap tag names, for example, in an HTML element with a class so that you can target it with CSS styles.

    Here’s an example of wrapping the whole thing in a div and each tag in a span element:

    $tags = get_tags();
    
    echo '<div class="tags">';
    foreach ( $tags as $tag ) {
    	if ( $tag->name == 'fill' ) {
    		continue;
    	}// do this for every tag you want gone
    	echo '<span class="tag-name">' . $tag->name . '</span> ';
    }
    echo '</div>';

    After making this change you can use a CSS snippet to target those elements, here’s an example using CSS:

    .tags {
    font-weight: bold;
    color: #222;
    }
    .tags .tag-name {
    display: inline-block;
    margin-left: 5px;
    }

    Depending on your theme you might need to make the class names more specific to avoid conflicting styles.

    You can read more about using CSS in WordPress in this article.

    Thread Starter anas33chaudhary

    (@anas33chaudhary)

    thank you very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to style php snippets echo’ is closed to new replies.