隐藏/禁用 WordPress 编辑器并使 Elementor 默认编辑器

问题描述 投票:0回答:2

我正在使用 Elementor,我想隐藏/禁用 WordPress 编辑器选项来编辑任何页面/帖子,而我只想显示“使用 Elementor 编辑”选项,即我想将 Elementor 设置为我的默认编辑器。 在图像中,您可以看到有一个选项“返回 WordPress 编辑器”,我只想在此处显示“使用 Elementor 编辑”,这样当我选择了类别和其他内容后,我就可以使用 Elementor 对其进行编辑。 我怎样才能做到这一点?

wordpress editor elementor
2个回答
1
投票

有人为此制作了一个插件:将 Elementor 设置为默认编辑器

但是,如果您需要对代码进行更多控制,这就是它的制作方式:

<?php

/**
 * Make Elementor the default editor, not the WordPress Editor (Gutenberg or Classic)
 * Clicking the page title will take you to the Elementor editor directly
 * Even non-Elementor-edited pages will become Elementor-edited pages now
 * You can revert by clicking the "Back to WordPress Editor" button
 *
 * Author:  Joe Fletcher, https://fletcherdigital.com
 * URL:     https://gist.github.com/heyfletch/7c59d1c0c9c56cbad51ef80290d86df7
 * Credit:  mjakic https://wordpress.stackexchange.com/questions/178416/how-to-change-the-title-url-on-the-edit-post-screen
 * Credit:  Aurovrata Venet https://developer.wordpress.org/reference/hooks/post_row_actions/
*/

/** Replace hyperlink in post titles on Page, Post, or Template lists with Elementor's editor link */
add_filter('get_edit_post_link', 'fd_make_elementor_default_edit_link', 10, 3 );
function fd_make_elementor_default_edit_link($link, $post_id, $context) {

    // Get current screen parameters
    $screen = get_current_screen();

    //check if $screen is object otherwise we may be on an admin page where get_current_screen isn't defined
    if( !is_object($screen) )
        return;

    // Post Types to Edit with Elementor
    $post_types_for_elementor = array(
        'page',
        'post',
        'elementor_library',
    );

    // When we are on a specified post type screen
    if ( in_array( $screen->post_type, $post_types_for_elementor ) && $context == 'display' ) {

        // Build the Elementor editor link
        $elementor_editor_link = admin_url( 'post.php?post=' . $post_id . '&action=elementor' );

        return $elementor_editor_link;
    } else {
        return $link;
    }
}

/** Add back the default Edit link action in Page and Post list rows */
add_filter( 'page_row_actions', 'fd_add_back_default_edit_link', 10, 2 );
add_filter( 'post_row_actions', 'fd_add_back_default_edit_link', 10, 2 );
function fd_add_back_default_edit_link( $actions, $post ) {

    // Build the Elementor edit URL
    $elementor_edit_url = admin_url( 'post.php?post=' . $post->ID . '&action=edit' );

    // Rewrite the normal Edit link
    $actions['edit'] =
        sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $elementor_edit_url ),
            esc_html( __( 'Default WordPress Editor', 'elementor' ) )
        );

   return $actions;
}


/** (optional) Remove redundant "Edit with Elementor" link added by Elementor itself */
add_filter( 'page_row_actions', 'fd_remove_default_edit_with_elementor', 99, 2 );
add_filter( 'post_row_actions', 'fd_remove_default_edit_with_elementor', 99, 2 );
function fd_remove_default_edit_with_elementor( $actions, $post ) {

  // Rewrite the normal Edit link
  unset( $actions['edit_with_elementor'] );

  return $actions;
}

/** Alternative:  Rewrite just the Edit link, and leave the page title as original */
/** Rewrite the normal Edit link on lists of Pages and replace it with Elementor's edit link */
// add_filter( 'page_row_actions', 'fd_elementor_modify_list_row_actions', 10, 2 );
// add_filter( 'post_row_actions', 'fd_elementor_modify_list_row_actions', 10, 2 );
// function fd_elementor_modify_list_row_actions( $actions, $post ) {

//      // Build the Elementor edit URL
//      $elementor_edit_url = admin_url( 'post.php?post=' . $post->ID . '&action=elementor' );

//      // Rewrite the normal Edit link
//      $actions['edit'] =
//        sprintf( '<a href="%1$s">%2$s</a>',
//         esc_url( $elementor_edit_url ),
//         esc_html( __( 'Elementor Editor', 'elementor' ) )
//          );

//     return $actions;
// }

0
投票

我已经上传并激活了这个 Make Elementor your default editor 插件,超链接现在显示的只是 WP 默认编辑器,如您在 screenshot 中看到的那样。

一个小背景故事:Elementor 发布 3.18.0 版本后,我完全失去了“使用 Elementor 编辑”按钮。我已经完成了各种故障排除,从清除缓存和检查 Elementor 设置到回滚到旧版本并恢复旧备份。它就是行不通。 所以按钮完全消失了,但 Elementor 仍然处于活动状态,因为我已经用它制作的元素确实出现在网站上。

如果您能帮我解决这个问题,我将不胜感激。如果您需要代码的任何部分,请告诉我。我不懂 php,但我是一名程序员,所以如果你给我一个修复的线索,我想我能够弄清楚。

© www.soinside.com 2019 - 2024. All rights reserved.