Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Code In WordPress

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #29477
    Unveiled
    Member

    I’m trying to show code in WordPress posts with the <pre> tag. I’m including a script in my theme, but my only problem is having the html tags automatically converted to entities like &lt; and &gt;

    Is there an automatic way to do this through the functions.php file?

    #78900
    Makeshift
    Member

    Here’s what I’d do..

    put this in your functions file:

    Code:
    function callback($buffer){
    $convert = “/([<])(.*)([>])/”;
    $replace = “<$2>”;
    $buffer = preg_replace($convert, $replace, $buffer);
    return $buffer;
    }

    and this goes after your opening pre tag:

    Code:

    and this before the closing pre tag:

    Code:

    the function will convert all of the brackets into the entities.

    #78903
    Unveiled
    Member

    Since I’m using WordPress, using PHP within my posts wouldn’t be ideal. I need a way to do this automatically.

    Edit: I’ve decided to deal with it and install the SyntaxHighlighter Evolved plugin instead of trying it myself.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.