HTML tags in WordPress image caption

I’m glad that better support should be added in version 3.4 but for now I’ve fixed the issue by changing the behaviour of image insertion so that it doesn’t use the shortcode. Here’s what I added to functions.php: add_filter( ‘disable_captions’, create_function(‘$a’, ‘return true;’) ); function image_send_to_editor_2($html, $id, $caption, $title, $align, $url, $size, $alt) { if … Read more

Float images in content

You need to setup CSS settings for alignleft class of your theme: .alignleft, img.alignleft { /* … */ display: inline; float: left; /* … */ } And you need to add editor stylesheet where the same CSS will be presented. Create editor-style.css file in your theme, put content CSS settings there and call add_editor_style(); from … Read more

How to get Text Selection in WordPress Editor

The visual editor is an TinyMCE implementation. The first way to repace a selected text, is to write a plugin for the TinyMCE. If you do not want to write a plugin, use the tinyMCE object: add_action( ‘admin_footer’, ‘tinyNagging’ ); function tinyNagging() { echo ‘ <script type=”text/javascript”> jQuery(document).ready( function() { window.setInterval( function(){ var selectedText = … Read more

unregister_sidebar() in stand-alone theme not working

Thanks to Milo and G.M. for pointing to the master key, as G.M. said: you have to use a lower priority than one register_sidebar runs, but lower priority means higher number. So the final code that is working: function site_unregister_sidebar() { if ( is_admin() && current_user_can(‘editor’) ) { unregister_sidebar( ‘my_custom_widget_area’ ); } } add_action(‘widgets_init’, ‘site_unregister_sidebar’, … Read more

wpautop – disable tags, keep tags

wpautop can ignore the linkebreaks if you use wpautop( $content, false ); To pass a parameter to wpautop via add_filter, use an anonymous function. This snippets seems to work for me if I add it to my theme’s functions.php: remove_filter( ‘the_content’, ‘wpautop’ ); $br = false; add_filter( ‘the_content’, function( $content ) use ( $br ) … Read more

Is there a plugin to insert pre-defined link into editor?

You can make a button to the Tinymce editor that adds a pre defined link like this youtube button: Put this in your functions.php theme file: // Hook into WordPress add_action(‘init’, ‘mylink_button’); // Create Our Initialization Function function mylink_button() { if ( ! current_user_can(‘edit_posts’) && ! current_user_can(‘edit_pages’) ) { return; } if ( get_user_option(‘rich_editing’) == … Read more

wp.media edit attachment screen

Long answer: Peeking into wp-includes/js/media-models.js, I see this: if ( ‘select’ === attributes.frame && MediaFrame.Select ) { frame = new MediaFrame.Select( attributes ); } else if ( ‘post’ === attributes.frame && MediaFrame.Post ) { frame = new MediaFrame.Post( attributes ); } else if ( ‘manage’ === attributes.frame && MediaFrame.Manage ) { frame = new MediaFrame.Manage( … Read more

How to get value of selected page template in Gutenberg editor?

I slightly modified SkyShab’s code, because it fired template change event on page load and it didn’t fire when template was changed to default (since getEditedPostAttribute( ‘template’ ) is then ”, which equals to null when testing for template change) const { select, subscribe } = wp.data; class PageTemplateSwitcher { constructor() { this.template = null; … Read more