最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

media - Front end wp_editor not rendering audiovideo links

matteradmin5PV0评论

I have an editor on the front end of a website using wp_editor. It mostly works as expected; very similar to the admin side editor. However, when I enter an audio or video link, the players are not rendered as they are on the admin side. For example, inputting:-

.mp3

...on the admin side will immediately render to the audio player. On my public side wp_editor, it remains as a URL string.

There are obviously some filters/scripts on the admin side that render these URLs that are not available as standard from the public facing side. Is it possible to get a public side wp_editor to behave exactly like the admin side editor? Its kind of pointless having front end editing if I lose a chunk of functionality from the admin side editor.

Im using my own custom plugin to launch the editor. Im using the following:-

function create_tinymce() {
    $settings = array(
        'media_buttons' => true,
        'drag_drop_upload' => false,
        'wpautop' => true,
        );
    wp_editor("", "my-editor", $settings);
}

Im then hooking the above function using:-

add_action( 'wp_head', 'create_tinymce', 0 );

I have an editor on the front end of a website using wp_editor. It mostly works as expected; very similar to the admin side editor. However, when I enter an audio or video link, the players are not rendered as they are on the admin side. For example, inputting:-

http://chromafunk/bucket/ring.mp3

...on the admin side will immediately render to the audio player. On my public side wp_editor, it remains as a URL string.

There are obviously some filters/scripts on the admin side that render these URLs that are not available as standard from the public facing side. Is it possible to get a public side wp_editor to behave exactly like the admin side editor? Its kind of pointless having front end editing if I lose a chunk of functionality from the admin side editor.

Im using my own custom plugin to launch the editor. Im using the following:-

function create_tinymce() {
    $settings = array(
        'media_buttons' => true,
        'drag_drop_upload' => false,
        'wpautop' => true,
        );
    wp_editor("", "my-editor", $settings);
}

Im then hooking the above function using:-

add_action( 'wp_head', 'create_tinymce', 0 );
Share Improve this question edited Jul 27, 2016 at 14:27 Michae Pavlos Michael asked Jul 27, 2016 at 12:27 Michae Pavlos MichaelMichae Pavlos Michael 691 silver badge12 bronze badges 3
  • How are you adding it to the frontend? Are you using a plugin? If not can you show us some of your code? – Fencer04 Commented Jul 27, 2016 at 13:23
  • Thanks Fencer. Ive appended my OP with some code examples. – Michae Pavlos Michael Commented Jul 27, 2016 at 14:27
  • There are 2 trac tickets regarding the oEmbed functionality outside of post/page edit screens here and here. It looks like it is on the radar but won't appear until an unspecified future release. – brianjohnhanna Commented Aug 3, 2016 at 15:58
Add a comment  | 

1 Answer 1

Reset to default 2

I've been fighting this for a while on a series of themes I make that provide a front end content creation interface not requiring a WP account. For the last two years I have said "trust me, URLs will embed".

Those old tickets are dormant, but I just have found a solution here https://wordpress.stackexchange/a/287623

For the template that renders the page you are using for your form, you need to add an enqueue statement.

This is some partial code on a site where auto embeds are not working on an editor added via wp_editor()

add_action('wp_enqueue_scripts', 'add_truwriter_scripts');

function add_truwriter_scripts() {  

    // set up main styles
    $parent_style = 'radcliffe_style'; 

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );

    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );



if ( is_page('write') ) { // use on just our form page

    // Get Embed functionality in rich text editor
    // h/t https://wordpress.stackexchange/a/287623
    wp_enqueue_script( 'mce-view' );
   :
   :
   // unrelated code follows
Post a comment

comment list (0)

  1. No comments so far