I want to add a table after the_content with a hook, but it's adding <p>
tags in certain areas. This is a plugin, I don't want to remove <p>
tags from all the_content, just the table I'm trying to add.
Here's an example, but my table is bigger and inside it's adding p tags in different spots.
function addTable( $content ) {
$table = '<table><tbody><tr><td>Example html here</td></tr></tbody></table>';
$content .= $table;
return $content;
}
add_filter( 'the_content', 'addTable', 20 );
Someone asked this in 2012, no answer but I'm trying to do the same thing: Adding a form at the end of the content
I do not want to remove <p>
tags from a theme's entire blog post, only the content I am appending. In this case, I'm appending a table.
Is there a way to disable the formatting for only the content I'm appending? Otherwise, how is it possible in WordPress to attach a form or table to a post with hooks without it adding formatting?
I want to add a table after the_content with a hook, but it's adding <p>
tags in certain areas. This is a plugin, I don't want to remove <p>
tags from all the_content, just the table I'm trying to add.
Here's an example, but my table is bigger and inside it's adding p tags in different spots.
function addTable( $content ) {
$table = '<table><tbody><tr><td>Example html here</td></tr></tbody></table>';
$content .= $table;
return $content;
}
add_filter( 'the_content', 'addTable', 20 );
Someone asked this in 2012, no answer but I'm trying to do the same thing: Adding a form at the end of the content
I do not want to remove <p>
tags from a theme's entire blog post, only the content I am appending. In this case, I'm appending a table.
Is there a way to disable the formatting for only the content I'm appending? Otherwise, how is it possible in WordPress to attach a form or table to a post with hooks without it adding formatting?
Share Improve this question edited Feb 19, 2022 at 21:19 Justin Breen asked Feb 18, 2022 at 21:16 Justin BreenJustin Breen 134 bronze badges 3 |1 Answer
Reset to default 0Pull from the provided answer back in 2012 and testing with the 2021 theme it works as intended.
function addTable( $content ) {
ob_start();
echo '<table><tbody><tr><td>Example html here</td></tr></tbody></table>';
$table = ob_get_clean();
$content .= $table;
return $content;
}
add_filter( 'the_content', "addTable", 20 );
add_filter
call,addTable
should be"addTable"
– Tom J Nowell ♦ Commented Feb 19, 2022 at 1:16