I want to place some other PHP tag inside the_content() is it possible somehow?
<?php the_content(
$custom_attach = get_post_meta( $post->ID, 'wp_custom_attachment', true );
$custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );
$name = 'button';
if ( ! empty( $custom_attach ) ) {
echo '<span class="icon-download">';
echo '<a href="'.$custom_attach['url'].'">'.$name.'</a>';
echo '<span>';
}
); ?>
I want to place some other PHP tag inside the_content() is it possible somehow?
<?php the_content(
$custom_attach = get_post_meta( $post->ID, 'wp_custom_attachment', true );
$custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );
$name = 'button';
if ( ! empty( $custom_attach ) ) {
echo '<span class="icon-download">';
echo '<a href="'.$custom_attach['url'].'">'.$name.'</a>';
echo '<span>';
}
); ?>
Share
Improve this question
asked Apr 13, 2020 at 21:05
DragutDragut
1732 gold badges2 silver badges11 bronze badges
2
|
1 Answer
Reset to default 1Why do you want to put your code between the braces in the_content()
? What are you trying to accomplish?
Maybe this solves your problem?
<?php
$custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );
$name = 'button';
if(!empty($custom_attach)) {
echo '<span class="icon-download">';
echo '<a href="'.$custom_attach['url'].'">'.$name.'</a>';
echo '<span>';
}
the_content();
?>
This echoes the <span>
-element with the class icon-download
first, and then the content of the post.
the_content()
accepts the 'read more link' text and a boolean 'stripteaser' argument... it does not accept any html tags. developer.wordpress/reference/functions/the_content - you could however use a filter function to append anything after or before or inside the content developer.wordpress/reference/hooks/the_content – Michael Commented Apr 13, 2020 at 22:09