Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

crayon on custom post type #67

coopersita opened this Issue Jan 12, 2013 · 14 comments


None yet
3 participants

Does it only work on Posts? It doesn't seem to work on my custom post types.



aramk commented Jan 13, 2013

It should work on anything that is filtered with the_posts, which includes pages.


aramk commented Jan 13, 2013

I just tested it with this:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'acme_product',
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'products'),

From http://codex.wordpress.org/Post_Types and it worked fine using the Twenty Twelve theme. Can you verify that works for you? I added code using the Tag Editor.

I see my problem now. It's in a custom field, in a custom post type. I guess it's the fact that it's in a custom field, not the custom post type...


aramk commented Jan 13, 2013

Hmm, I think so. You could try to add the filter "the_content" to that
content before printing it, or use CrayonWP::highlight("some content") but
keep in mind that without the Tag Editor you'll need to ensure encoding
yourself. Using the pre tag is probably better in this case despite the
fact you have to write it yourself.

On 13 January 2013 14:04, coopersita notifications@github.com wrote:

I see my problem now. It's in a custom field, in a custom post type. I
guess it's the fact that it's in a custom field, not the custom post

Reply to this email directly or view it on GitHubhttps://github.com/aramkocharyan/crayon-syntax-highlighter/issues/67#issuecomment-12188882.

I'm using Advanced Custom Fields. The code does get insterted as a <pre class="lang:java decode:true "> tag, but the rest doesn't seem to kick in. Also, the problem is that no all the content is code, so some would be regular text, and some code in it. Is this possible, or should I look for a different solution/plugin?


aramk commented Jan 13, 2013

Ah ok. Add a WYSIWYG Editor field and then when it tells you to add this:

<?php the_field('wysiwyg_test'); ?>

Add this instead:

<?php echo CrayonWP::highlight(get_field('wysiwyg_test')); ?>

@aramk aramk closed this Jan 13, 2013


aramk commented Jan 13, 2013

PS: The WYSIWYG means you can use the Tag Editor (<>).

That's just awesome! Thanks!

The only thing is that it uses the default theme, and options, instead of the user defined ones, but I can live with it.


aramk commented Jan 13, 2013

It shouldn't if you override it:

Screen Shot 2013-01-13 at 3 09 37 PM

It just doesn't... It changes when it's a preset themes, but not to user-defined ones (it reverts to default). The user-defined works fine when added normally, on a regular post.

Something else I've noticed, is that when I set it to "Wrap lines by default", the numbers are all bunched up in the first line:

2013-01-13 11 18 54 am


aramk commented Jan 14, 2013

Could you give a URL? It's working for me but from the toolbar I can see that the CSS seems to be breaking, probably due to specificity with other styles on the page. The height isn't correctly being set for the lines - most likely it's being set to undefined or 0 or something.

@aramk aramk reopened this Jan 14, 2013


aramk commented Feb 10, 2013

I believe this problem is fixed now with some js updates to the height setting.

@aramk aramk closed this Feb 10, 2013

When using CrayonWP::highlight() I get:

Warning: Cannot modify header information - headers already sent by (output started at .../header.php:2) in .../wp-content/plugins/crayon-syntax-highlighter/crayon_wp.class.php on line 219

Headers should not be set after Wordpress/Theme have already set them. Can you update your code to only print headers when needed. I am assuming this is for AJAX calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment