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

Comments

@gregoirenoyelle
Copy link

@gregoirenoyelle gregoirenoyelle commented Jan 30, 2014

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

@georgestephanis georgestephanis commented Jan 30, 2014

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

@gregoirenoyelle gregoirenoyelle commented Jan 30, 2014

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

@georgestephanis
Copy link
Member

@georgestephanis georgestephanis commented Jan 30, 2014

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

@mattwiebe mattwiebe commented Jan 30, 2014

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' ).

@mattwiebe mattwiebe closed this Jan 30, 2014
@georgestephanis
Copy link
Member

@georgestephanis georgestephanis commented Jan 30, 2014

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

@gregoirenoyelle
Copy link
Author

@gregoirenoyelle gregoirenoyelle commented Jan 30, 2014

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

@georgestephanis georgestephanis commented Jan 30, 2014

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

@gregoirenoyelle
Copy link
Author

@gregoirenoyelle gregoirenoyelle commented Jan 30, 2014

Yes I do.

@jeherve
Copy link
Member

@jeherve 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

@gregoirenoyelle gregoirenoyelle commented Jan 31, 2014

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

@jtremback jtremback commented Mar 26, 2014

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

@vtmx
Copy link

@vtmx vtmx commented Oct 24, 2014

Jetpack Markdown for me worked with the plugin Typewriter.

@vtmx
Copy link

@vtmx 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.