I have a piece of code that outputs my post title but how can I output it as an H4?
Here is the code I have: <?php echo get_the_title( $post_id ); ?>
Thanks
Using your example, you could...
<h4><?php echo get_the_title( $post_id ); ?></h4>
Or
$h4 = get_the_title();
echo '<h4>' . $h4 . '</h4>';
More on get_the_title().
Or you could use the_title().
the_title( '<h4>', '</h4>' );
The most simple way is:
<h4><?php echo get_the_title( $post_id ); ?></h4>
However, if you want check first if that post has a title and avoid an empty <h4>
if it doesn't, you write:
$title = get_the_title( $post_id );
if ( $title )
echo "<h4>$title</h4>";
<h4><?php echo get_the_title( $post_id ); ?></h4>
the_title()
as suggested in the answer. That way, though, you wouldn't be able to set the post ID the same way you could set it withget_the_title()
.