February 5, 2014 at 3:32 am #219738
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
<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?
MattFebruary 5, 2014 at 3:56 am #219741
The way I do it is by embedded gists. I use this plugin on my personal site: https://github.com/manovotny/wp-gist 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.
DevinFebruary 6, 2014 at 10:27 am #220395
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.
February 7, 2014 at 3:02 am #220750
- This reply was modified 9 years, 10 months ago by MM.
- The topic ‘Displaying HTML code snippets’ is closed to new replies.