I’ve got a post format of Image, and I am running into an issue where the image is being wrapped by a <p>
tag. I want to get rid of that tag (specifically on the single.php
version) of those post types.
How can I get inside the formatting in a theme and remove the <p>
tags, or create any format that I want for the output of this type of post, without affecting posts of a different post format?
By default, WordPress adds paragraph
tags to category descriptions. Stop this by adding the following to your functions.php file
Simple and easy (codeless).
Thank you
WordPress automatically ads the
<p>
tags to the content. So it shows up while loading the content. This is with the filterwpautop
. So we will remove this filter for theimage
post type only. You can manage this by adding the following code in functions.php file.is_single()
checks if a single post is being displayed.If this post type is called “image”, you can create a single template to handle the display of just the image post type.
Just copy your ‘single.php’ file and rename the copy ‘single-image.php’. Now you can control just the image posts. To strip out tags, I like to use the
strip_tags()
function. If you print the content of the post withthe_content()
it already applies the content filter, wrapping lines in<p>
tags.Here is an example of how you could get the content of your image without the tags:
Hope this helps!
You can use
get_the_content()
instead ofthe_content()
.This may solve your problem and another solution is same as described by @Chittaranjan
Simply add below line of code in your theme’s functions.php file
For content :
For excerpt
learn more : https://codex.wordpress.org/Function_Reference/wpautop
You can use specific post class for the
single-post
orsingle-format-standard
and make it hide as you require only in a single page so that it won’t be a conflict for other parts of the website.Example CSS Code*
Example CSS Code for specific post format Image
Inorder to remove the p tag from the content you can use the below code
Another way to code it based on the solution by @chittaranjan
put this code in “style.css” of “Active child theme”
if want to remove from particular page or post you can call this
Using
wp_strip_all_tags
you can get rid of all html tags including p, div and etchttps://developer.wordpress.org/reference/functions/wp_strip_all_tags/
wp_strip_all_tags(category_description());
though the query has been answered, I’m posting the below for further reference.
Source