Title: Link class doesn&#039;t work?
Last modified: August 22, 2016

---

# Link class doesn't work?

 *  [Phoenix39](https://wordpress.org/support/users/phoenix39/)
 * (@phoenix39)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/)
 * I’ve made a custom design for wordpress posts, and everything works except the
   last part where I have a “block” that’s showing the category the post was published
   in.
 *     ```
       <div class="post">
       	<h4><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h4>
       	<span class="postinfo">Publisert <?php the_date(); ?></span>
       	<div class="utdrag">
       		<?php the_excerpt(); ?>
       	</div>
   
       	<a href="#" class="block"><?php the_category( $id ); ?></a>
       </div>
       ```
   
 * I’ve had this problem before, that the class won’t work together with a wordpress
   php code. What should I do?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/#post-5647244)
 * Can you post a link to a site that shows the issue?
 *  Thread Starter [Phoenix39](https://wordpress.org/support/users/phoenix39/)
 * (@phoenix39)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/#post-5647247)
 * Sorry, it’s on XAMPP (localhost)…
 * i’ve made a css code for class=”block” that works perfectly by itself, but with
   the php code in the example above, the text shows up outside the box… first, 
   the box shows up, then the text below.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/#post-5647263)
 * Ah, I see what the issue is. `the_category()` returns an `<a>` tag as part of
   its output, so your code outputs two `<a></a>` tag pairs next to each other. 
   You could try either filtering the output of `the_category()` or try some code
   like this:
 *     ```
       <?php
       $categories = get_the_category();
       foreach ( $categories as $category ) {
         printf( '<a href="#" class="block">%1$s</a>', $category->name);
       };
       ?>
       ```
   
 *  Thread Starter [Phoenix39](https://wordpress.org/support/users/phoenix39/)
 * (@phoenix39)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/#post-5647266)
 * That seems to work, thank you!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Link class doesn't work?’ is closed to new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [Phoenix39](https://wordpress.org/support/users/phoenix39/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/link-class-doesnt-work/#post-5647266)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
