Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #219738

    Hi guys,

    I’ve been trying to display some simple HTML code snippets for the user to copy (the HTML is for an image that is then hyperlinked to a page on my site – I am basically creating banners for my users to add to their own site).

    I’ve tried the <code> and <pre> tags inside a text block using the correct character entities to avoid the HTML being rendered. I also tried putting it into a Notification Box and neither method worked. Well, it did work the first time but as soon as I tried to edit the code snippet, the character entities were automatically replaced and so the HTML was rendered.

    How can I best add some simple HTML code snippets to a page or post without having to completely redo it everytime I want to edit it?




    Hey meanster99!

    The way I do it is by embedded gists. I use this plugin on my personal site: so that they can be added in as little shortcodes pointing to my gists.

    I found it to be the most reliable method of sharing snippets within any WordPress theme.



    Hi Devin,

    Thanks for the tip – I tried gist but they closed my account because they said I was spamming! I only created about 5 gists for image links to my site. I reckon I could carry on as an anonymous user and be OK, but my client wasn’t that happy with the size of the embedded gist box and the ” hosted with ❤ by GitHub” on the bottom (as the code is essentially only 1 or 2 lines long, there is almost more reference to github than the code itself!).

    I’ve since discovered CodePen, which is much the same as gist, although I’m still not happy with all the extraneous links on the code box itself.

    I think I will just stick with using <pre> tags and I’ll create a text file with all the links on for quick reference, then if I need to edit the page again (and WP screws up my code) I’ll have a quicker way of redoing it. Not convenient but makes for cleaner code boxes, which is important for my client’s site.



    • This reply was modified 9 years, 10 months ago by MM.

    Glad we could help. Let us know if you have any other questions or issues.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Displaying HTML code snippets’ is closed to new replies.