Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For link post formats to appear in my archive.php I'm using the following code:

<a href="<?php echo wp_trim_words( get_the_content(), 100 ); ?>">
<?php the_content(); ?>
</a>

Of course, this creates a validation error due to a <p> being inside an <a>. I'm seeking a solution to fix this validation error.

This is the most intuitive way I can dream up for easy link post formats (of course, I'm open to suggestions).

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can temporarily remove the filter that adds paragraph tags:

// remove the filter
remove_filter( 'the_content', 'wpautop' );

// output content
the_content();

// add the filter again
add_filter( 'the_content', 'wpautop' );
share|improve this answer
    
I'm not sure this is a satisfying solution. –  AndrettiMilas Oct 4 '12 at 18:09
    
@siouxfan45 perhaps elaborate on why it's not? –  Milo Oct 4 '12 at 19:01
    
If put in functions.php, this will remove the <p> tag from all occurrences of the_content. I'm seeking to remove it in this one scenario. –  AndrettiMilas Oct 4 '12 at 20:59
    
@siouxfan45 which is why above I remove the filter, output the content, then immediately re-add the filter. this would go directly in your template where you want the content to appear without p tags, not in functions.php –  Milo Oct 4 '12 at 21:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.