Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Markdown in Custom Fields #155

Closed
gregoirenoyelle opened this issue Jan 30, 2014 · 13 comments
Closed

Use Markdown in Custom Fields #155

gregoirenoyelle opened this issue Jan 30, 2014 · 13 comments
Assignees
Labels
[Feature] Markdown [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Comments

@gregoirenoyelle
Copy link

Hi
Thanks for the Jetpack update 2.8 Beta 1
I use a lot Markdown. It works well in Editor but not yet in Custom fields like Excerpt or Custom Meta made with Advanced Custom Fields.
Do you plane to support this?
Thanks!
Grégoire

@georgestephanis
Copy link
Member

cc: @mattwiebe

@ghost ghost assigned mattwiebe Jan 30, 2014
@gregoirenoyelle
Copy link
Author

Thanks Georges.
After few tests, it do not works either in custom post type traditionnal editor.
Grégoire

@georgestephanis
Copy link
Member

This could be a wontfix issue -- we can't apply it to every field when it's saved, so custom fields may need some way added to attach the markdown parser. I leave that call to Wiebe, though, he knows how it's architected best.

@mattwiebe
Copy link
Contributor

Supporting Markdown in plugins like ACF will be left to those plugins if they wish to do so. The function you'd need would be WPCom_Markdown::get_instance()->transform( $content ). See the function for args, noting especially unslash.

As for custom post types, support can be added for them via add_post_type_support( 'your-post-type', 'wpcom-markdown' ).

@georgestephanis
Copy link
Member

Also, you'd need to jetpack_require_lib( 'markdown' ); first -- just to make sure the class is loaded up.

@gregoirenoyelle
Copy link
Author

Thanks for your comments.
I will send this issue to Elliot (ACF).
I put in my functions.php

add_post_type_support( 'your-post-type', 'wpcom-markdown' )

But it change nothing. I miss the second one. How can I add it?
Perharps you can add a special parameter we use in CPT args > supports
Cheers

@georgestephanis
Copy link
Member

You do need to switch out your-post-type with the actual post type slug you had chosen.

@gregoirenoyelle
Copy link
Author

Yes I do.

@jeherve
Copy link
Member

jeherve commented Jan 31, 2014

I put in my functions.php
add_post_type_support( 'your-post-type', 'wpcom-markdown' )
But it change nothing.

I was able to get Markdown to work on a Custom Post Type by adding the following to a functionality plugin:

add_action('init', 'my_custom_init');
function my_custom_init() {
    add_post_type_support( 'product', 'wpcom-markdown' );
}

Ref

Perharps you can add a special parameter we use in CPT args > supports

That's already possible. If you can change the code generating the custom post type, you can add Markdown support like so:

// Register Custom Post Type
function custom_post_type() {

    $labels = array(
        'name'                => _x( 'Products', 'Post Type General Name', 'text_domain' ),
    );
    $args = array(
        'label'               => __( 'product', 'text_domain' ),
        'supports'            => array( 'title', 'editor', 'publicize', 'wpcom-markdown' ),
    );
    register_post_type( 'product', $args );

}
// Hook into the 'init' action
add_action( 'init', 'custom_post_type', 0 );

I tested it on a test site of mine and it works.

@gregoirenoyelle
Copy link
Author

It works perfect. Thanks a lot Jeremy for all your support!
I will writte a tutorial about that and here is the
message from ACF. Good new!
Cheers
Grégoire

@jtremback
Copy link

This worked for me, putting markdown in a custom post type.

@vtmx
Copy link

vtmx commented Oct 24, 2014

Jetpack Markdown for me worked with the plugin Typewriter.

@vtmx
Copy link

vtmx commented Oct 26, 2014

Now I added the plugin: (Markdown Extra) [https://littoral.michelf.ca/code/php-markdown/php-markdown-extra-1.2.8.zip]

And add-on: (ACF Wordpress Wysiwyg Field)[https://github.com/elliotcondon/acf-wordpress-wysiwyg-field]

In functions.php I added:

// style editor
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_content', 'wptexturize' );
remove_filter( 'the_excerpt', 'wpautop' );
remove_filter( 'the_excerpt', 'wptexturize' );
remove_filter( 'acf_the_content', 'wpautop' );
remove_filter( 'acf_the_content', 'wptexturize' );

// markdown support
add_filter( 'the_content', 'Markdown' );
add_filter( 'the_excerpt', 'Markdown' );
add_filter( 'acf_the_content', 'Markdown' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Markdown [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

No branches or pull requests

6 participants