• Resolved americo2016

    (@americo2016)


    Hi everyone,

    I have a template where the post titles has two words and each word in different h-tag like this: “Hello world” where “Hello is in a h1-tag and world” in a h3-tag. Searching in the forum I found this code to split the title:
    <h1><?php echo str_replace(' ','<br />',get_the_title()); ?></h1>
    And as you can see I get the title in two lines but still in the same h1-tag.

    How can i inject the h3-tag to wrap the second word?

    thank you for your help!!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You probably want to do a bit of review on the php explode() function which allows you to split a string by another string. It would probably look something like this:

    $mytitle = get_the_title();
    $pieces = explode(" ", $mytitle);
    echo "<h1>". $pieces[0]."</h1><h3>". $pieces[1]."</h3>";

    Please keep in mind that the H1 line and the H3 will be on separate lines by default.

    Thread Starter americo2016

    (@americo2016)

    Excellent. It just work perfectly.

    Every day I learn something new, Thanks very much!!!

    Glad to help. Good luck with your project.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Split post title in two different h-tag’ is closed to new replies.