Ich entwickle ein Thema, in dem ich einen Front-End-Bereich haben möchte, aber wenn ich versuche, die wp_editor()
in die Seitenvorlage aufzunehmen, erhalte ich das folgende Ergebnis:
P.S. Der WordPress-Editor funktioniert im Dashboard einwandfrei.
Pietro
Vermutung, verwenden Sie _
(Unterstrich) in Ihrer Editor-ID? Wenn ja, entfernen Sie sie und verwenden Sie nur Kleinbuchstaben. So etwas wie thisismyeditorid
.
Aus dem Codex ..
Beachten Sie, dass die an die Funktion wp_editor () übergebene ID nur aus Kleinbuchstaben bestehen kann. Keine Unterstriche, keine Bindestriche. Alles andere führt zu Fehlfunktionen des WYSIWYG-Editors.
Sie müssen zuerst die Variablen $settings
und $editor_id
und $content
definieren. Dann können Sie wp_editor()
anrufen.
So etwas sollte für Sie funktionieren:
// default settings
$content = 'This content gets loaded first.';
$editor_id = 'my_frontend_editor';
$settings = array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => '',
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (supported on the front-end in WordPress 3.4)
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
);
wp_editor( $content, $editor_id, $settings );
Denken Sie daran, dass Variablen definiert werden müssen, bevor Sie sie verwenden können.
So zeigen Sie es in einer Vorlage an:
<?php
/*
Template Name: Template-Editor */
?>
//have to load all the scripts and header info
<?php get_header(); ?>
<?php
$content = 'Initial content for the editor.';
$editor_id = 'editor';
$settings = array(
'wpautop' => true, //Whether to use wpautop for adding in paragraphs. Note that the paragraphs are added automatically when wpautop is false.
'media_buttons' => true, //Whether to display media insert/upload buttons
'textarea_name' => $editor_id, // The name assigned to the generated textarea and passed parameter when the form is submitted.
'textarea_rows' => get_option('default_post_edit_rows', 10), // The number of rows to display for the textarea
'tabindex' => '', //The tabindex value used for the form field
'editor_css' => '', // Additional CSS styling applied for both visual and HTML editors buttons, needs to include <style> tags, can use "scoped"
'editor_class' => '', // Any extra CSS Classes to append to the Editor textarea
'teeny' => false, // Whether to output the minimal editor configuration used in PressThis
'dfw' => false, // Whether to replace the default fullscreen editor with DFW (needs specific DOM elements and CSS)
'tinymce' => true, // Load TinyMCE, can be used to pass settings directly to TinyMCE using an array
'quicktags' => true // Load Quicktags, can be used to pass settings directly to Quicktags using an array. Set to false to remove your editor's Visual and Text tabs.
'drag_drop_upload' => true //Enable Drag & Drop Upload Support (since WordPress 3.9)
);
wp_editor( $content, $editor_id, $settings );
?>
//have to include the footer info
<?php get_footer(); ?>
Oder Sie können einen leeren Editor mit den Standardeinstellungen einzeln anzeigen:
<?php
$content = '';
$editor_id = 'mycustomeditor';
wp_editor( $content, $editor_id );
?>
Dokumentation: https://codex.wordpress.org/Function_Reference/wp_editor