How can I do syntax highlighting for files included with a custom shortcode?

I'm writing a tutorial on using the R language to do some applied statistics. An example post is: http://mcmcinirt.stat.cmu.edu/archives/223 This answer taught me how to develop a custom shortcode so that I can include files stored on the webserver directly into the post. It works great. However, if possible, I'd like to have syntax highlighting too instead of 'just' the <pre> tag rendering. My initial attempt was to change the output of the shortcode function from: return '<pre>'.$file.'</pre>'; to return …
Category: Web

Wordpress 5.1 and Syntax highlighter, problem with HTML encoded special characters

I'm using Wordpress 5.1 and Gutenberg block editor. I'm trying to show some Java code with the plugin SyntaxHighlighter Evolved. When editing a post I use the block 'Custom HTML' then add the code [code language="java"] List<Integer> myList = new ArrayList<>(); [/code] Then I save the post and the Java code will appear correctly with syntax highlighting applied to it. It will look like this This is the result that I wanted. But a problem happens when I edit the …
Category: Web

Highlight inner post menu current item

WordPress has a built in feature that assigns the class “current-menu-item” to the current navigation item. Nevertheless, that feature only works for contextual menus; and not for the ones inside the post content. You can see in this page that the first level parent item OBRAS is highlighted, but not the third level child GRÁFIKA located left in the inner page menu. Looking for a method to accomplish this highlight feature in the inner menu. Thanks
Category: Web

Multi Language Code Snippet in Wordpress

I write Programming articles in my Wordpress website. My articles contain content for different languages with code samples. I want to allow user to choose which programming language he prefer. Example from Android documentation where user can chose Kotlin or Java code:
Category: Web

highlight parent page menu item when in custom post type

in a website that I am building I have a portfolio custom post types (called: "project") to show my portfolio items. The page that holds the loop of the custom post type is a custom page called "Portfolio" this page has only thumbnails and each thumbnail is linking to a custom post type: http://www.tipoos.com/new/?page_id=43 notice when inside the portfolio page above the upper menu is highlighting the current page like other pages in the site. when entering a post type …
Category: Web

Proper implementation/use of code/syntax highlighting

I've already read what I can on a couple of sites and installed this plug-in: http://en.support.wordpress.com/code/posting-source-code/ http://alexgorbatchev.com/SyntaxHighlighter/ I'm missing how to make it work. Now I have two questions: Do I have to type in the Visual window or the HTML window? Does TinyMCE mess with this? I've seen my code disappear in the HTML window. I currently have typed in my code in Visual Window like this: [sourcecode language="php"] <? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://CMSTrainingVideos.com" …
Category: Web

How to work with Syntax Highlighter Evolved?

I have installed Syntax Highlighter Evolved to simplify code snippets writing and highlighting. I know that it is quite popular and used by many bloggers, so I must be doing something wrong because it drives me mad. I'm writting my first blog post and I want to include several C# and XML code snippets. I can include one snippet format it as I need but when I continue with second snippet (switching between HTML and Wysiwyg editor and saving draft …
Category: Web

What theme is good for posting code?

I have my blog hosted at www.alphaot.com and I guess it's good enough. But problems arise when the lines of code get longer than 30 characters. The lines just wrap and get icky or something they even don't wrap! In your experience what's a great WordPress theme for a developers blog to post code to? Also, I'm using Windows Live Writer, any extensions for code publishing you would recommend? Edit: More than plugins, I'm interested on a clean, free wordpress …
Category: Web

Visual Editor not working properly

I have facing this issue since last one month. I would like to display my source code using the Syntax Highlighter so i have changed my editor mode from visual to text. I put my code in [html] <div class="panel panel-default panel-faq"> <div class="panel-heading"> <a data-toggle="collapse"> <h4 class="panel-title"> Questions </h4> </a> </div> </div> [/html] Then i switched to visual mode then the editor is give a new line space between the html code. like bellow. [html] <div class="panel panel-default panel-faq"> …
Category: Web

My Syntax Highlighter Died, What Now?

On my wordpress install (hosted by 1&1) a few years back I installed "Syntax Highlighter for WordPress" (I'm currently at 3.0.83.3) Everything was going great until yesterday when something got updated and now my syntax highlighting doesnt work. I can see when "view source" that the <pre> tag that is created by my [cpp] tag is immediately closed on the same line instead of waiting for the [/cpp] tag. It's a bit strange. Anyways, I went to check if there …
Category: Web

Embedding code snippets in posts with indentation

I have a privately hosted blog using WordPress, and I am using the SyntaxHighlighter Evolved plugin for displaying highlighted code snippets nicely. I use the built-in editor in WordPress for writing my posts, but whenever I paste in code snippets, they lose all the formatting they had (indentation). This makes it very hard to create code snippets and share on my blog. Am i missing anything? Is there any easy way to paste code snippets while keeping their formatting ? …
Category: Web

Source code get entity escaped after migrating

I have a lot of posts with source code on it. After migrating my blog from wordpress.com to self-hosting, the source code all have HTML entity escaping, for example: [code] printf("hello"); [/code] This causes the rendered source code become printf("hello") instead of printf("hello") I think this is because the export/import process was using xml file where all non-suitable characters get escaped. Is there anyway only normal content get escaped, but not [code] enclosed content when migrating wordpress?
Category: Web

Code Highlighting in BlockQuote

Many of my Wordpress Blog(http://subinsb.com/) posts have code snippets which is wrapped in blockquote elements. I need to highlight these code snippets. I tried using GeSHi, Prettify Code Syntax, CodeColorer but none of them works for blockquote elements. Is there any plugin that supports code highlighting for blockquotes ? OR How can I customize the current highlighting plugins to highlight blockquote elements too ?
Category: Web

Syntax Highlighter XML striping

I am really frustrated with availible Syntax Highlighter's on the market it seems that no matter which one I use, after pressing "Save Draft" or "Publish" and after I change from Visual to Html or reverse I am loosing the xml snippet code. Also, other code (C#, PHP) just loosing their style, especially break lines making code unreadable. My configuration is WordPress 3.2.1. Easy Google Syntax Highlighter, SyntaxHighlighter TinyMCE Button, SyntaxHighlighter I really like WordPress however writing and espessially editing …
Category: Web

Displaying syntax highlighted code

I have a blog that I write up entries for that sometimes has programming code as part of the text within my writing's. Normally I use the quote function to give it a bit of highlighting, but was wondering if there's a better way that anyone has come across in their travels. Something that could do this for example: function foo() { $var = "bar"; } to highlight various property for the code like an IDE would. Thought that this …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.