0

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).

1

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' );
4
  • I'm not sure this is a satisfying solution. 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. 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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