• Resolved Nic727

    (@nic727)


    Hi,

    I’m a newbie developing my own theme.

    I currently hard-coded my page title as <h1>, but I would like to know what’s the best way to code in WordPress between :

    <h1><?php echo the_title(); ?></h1>

    or

    <?php the_title( '<h1>', '</h1>' ); ?>

    I guess it’s doing the same thing at the end, but what’s the most used way by devs?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, since the_title() function echoes its result, your first sample is no good.
    It doesn’t really matter what others are doing. You can write it however you want.
    For instance, my theme uses a function that filters for attributes, so I pass all my HTML through that. If you don’t want to do that, you can at least consider that core functions are usually filtered, so you give child themes and plugins a chance to modify things if you pass parameters through functions with filters.

    Thread Starter Nic727

    (@nic727)

    I want to add dynamic page title in this code

    <section class="page-header"> 
        <div class="featured-image-container"> 
            <div class="featured-image" style="<?php if($page_image) echo 'background-image:url(\''.$page_image[0].'\')' ?>"></div>                 
            <div class="img-overlay"></div>                 
            <div class="page-title"> 
                <h1>TITLE HERE</h1> 
            </div>                 
        </div>             
    </section>   

    I know for category.php it’s <?php echo single_cat_title(); ?>, so I thought that the_title() was doing the same thing for posts and pages…

    • This reply was modified 3 years, 7 months ago by Nic727.
    • This reply was modified 3 years, 7 months ago by Nic727.

    Suggest that you download and review the available themes and let us know what you find.
    The point of having your text and page structures subject to filters and hooks is well made.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Best markup for WordPress?’ is closed to new replies.