WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Putting the last character of the_content() inside a tag (3 posts)

  1. koyder
    Member
    Posted 3 years ago #

    Hello,
    I'd like to put the very last character of the_content() inside a <span> tag, no matter what the character is. I was able to put an empty <span></span> tag after the last character with this code:

    $content = get_the_content()."<span></span>";
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;

    But that doesn't satifty me. I'd greatly appreciate any help!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    $content = get_the_content();
    $content = substr($content,0,strlen($content)-1)."<span>".substr($content, -1)."</span>";
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;

    http://php.net/manual/en/function.substr.php
    http://www.php.net/manual/en/function.strlen.php

  3. koyder
    Member
    Posted 3 years ago #

    Thank you very, very much!

Topic Closed

This topic has been closed to new replies.

About this Topic