Tet banner

Custom Fields
Support General WYSIWYG Field not swapping between editor modes

  • Creator
  • #11514
    Resolved SLG Marketing

    I have added the WYSIWYG editor on a custom post type but I can't toggle between the visual and plain text editors.

    I'm getting the following error in my dev console:

    TypeError: j is undefined[Learn More] 3 load-scripts.php:702:681
    e http://localhost/wp-admin/load-scripts.php:702:681
    c/< http://localhost/wp-admin/load-scripts.php:702:271
    C http://localhost/wp-includes/js/tinymce/wp-tinymce.php:3:11105
    d http://localhost/wp-includes/js/tinymce/wp-tinymce.php:3:11256

    My code for the metaboxes is:

    public function generateMetaBox($meta_boxes){
        $prefix = strtolower($this->attributes['post']['single']);
        // Content Area
            'title'=>'Case Study Content',
            'post_types' => $this->attributes['post']['slug'],
            'context'    => 'normal',
            'priority'   => 'high',
            'fields' => array(
                    'name'          =>  'cs-content',
                    'desc'          =>  'THIS NEEDS SOME INSTRUCTIONAL COPY',
                    'id'            =>  $prefix . '_content_group',
                    'type'          =>  'group',
                    'clone'         =>  true,
                    'sort_clone'    =>  true,
                    'fields'        =>  array(
                    'name'  => 'Content Block',
                    'desc'  => 'Content block test',
                    'id'    => $prefix . '_content',
                    'type'  => 'wysiwyg',
        return $meta_boxes;

    There are no other plugins installed and the CPT doesn't have the standard editor.

    What am I doing wrong here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
  • #11534
    Anh Tran


    I've just tried your code and it works for me. Here is my screenshot:

    View post on imgur.com

    I think the problem might come from another part that has JavaScript error. Any JS error can breaks the execution of other JS, which might include the JS for the editors. Can you add these lines to wp-config.php and see what's in the console:

    define( 'WP_DEBUG', true );
    define( 'SCRIPT_DEBUG', true );
    define( 'CONCATENATE_SCRIPTS', false );
    SLG Marketing


    Sorry for taking so long to reply, I've been on another project. This is the output:

    TypeError: textarea is undefined[Learn More] editor.js:100:5
    switchEditor http://localhost/wp-admin/js/editor.js:100:5
    init/< http://localhost/wp-admin/js/editor.js:34:7
    C http://localhost/wp-includes/js/tinymce/tinymce.min.js:2:11105
    d http://localhost/wp-includes/js/tinymce/tinymce.min.js:2:11256

    Any ideas?

    SLG Marketing

    I should add that we are using the classic editor and WP 4.9.8. No other plugins are installed.

    Anh Tran

    Hi, can you send me a temporary admin account? I'll check that for you.

    SLG Marketing

    Not really as this is a local development site. I'll see about deploying it somewhere for you to test.

    In the meantime I'll try reinstalling the Metabox plugin.

    SLG Marketing

    I have set up a demo site for you to debug on. let me know if there is anything else you need.

    Anh Tran

    Thanks for the info. I'm checking your site and found a problem: the ID of the field contains a space:

    View post on imgur.com

    That comes from the $prefix = strtolower($this->attributes['post']['single']);, which transform Case Study to just case study. It should be case_study. Please try this code:

    $prefix = str_replace(' ', '_', strtolower($this->attributes['post']['single']));

    The space in field ID (and then in the input name/ID) causes unexpected behavior, and that might be a cause to this problem.

    SLG Marketing

    Great spot! Thank you so much! It was driving me up the wall.

    Thanks again, this has restored the anticipated behaviour.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.