Puddinq.com sharing knowledge

ACF code field – SyntaxHighlighter Evolved

ACF code field - SyntaxHighlighter Evolved

syntaxhighlighter evolved

In this new project I wanted to hav an ACF repeater field with the SyntaxHighlighter Evolved code block in it. The code would not render anyway I tried to output it in my template. I have had a look in the ‘SyntaxHighlighter Evolved code’ plugin and found there were three hooks (saving, calling and rendering) that were added to make code in content render pretty. The replication of this for acf fields felt to vulnarable for future updates and I came with another solution working great:

  1. Create a custom post type for the blocks (hidden post type)
  2. Add a (repeater field with) a relational field to the main post
  3. Select the required posts with the created code ‘in the repeater’

In your template (main post) where you would like ti display the code fields add the post by filtering the content:


    $code = get_post(48);

    echo apply_filters('the_content', $code->post_content);