Hot answers tagged

41

Welcome to WordPress stack exchange! Just yesterday I created WP-Markdown, which enables Markdown on your posts. It also provides the same interface as this website (the toolbar, and live preview) - however, currently only for comments and bbPress forums (if enabled). That said, (since it would be straightforward to do), I am planning on adding an option ...


19

It's actually not too bad to do what you're asking. This should take you about an hour to do your first one, and 10 minutes to do subsequent ones. Ultimately what you're going to do is create a TinyMCE plugin. Here's what you should arm yourself with to start: General guide to creating a tinymce plugin Example code from WordPress Core A general guide on ...


19

For Gutenberg to work in a Custom Post Type you need to enable both the editor in supports (which you already have) and show_in_rest. So add 'show_in_rest' => true, to your post registration arguments array.


17

Not sure if this still works. Preferably, drop this inside your theme's functions.php: add_filter( 'user_can_richedit' , '__return_false', 50 );


16

I recently got this working. You should search and replace metaname with your meta box name. The key to maintaining formatting was using wpautop(); when saving the data. add_action( 'add_meta_boxes', 'add_metaname_box'); add_action( 'save_post', 'metaname_save'); function add_metaname_box() { add_meta_box( 'metaname_id', __( 'metaname ...


14

Just replace the default output. Make sure you unescape the excerpt before you send it to the editor: add_action( 'add_meta_boxes', array ( 'T5_Richtext_Excerpt', 'switch_boxes' ) ); /** * Replaces the default excerpt editor with TinyMCE. */ class T5_Richtext_Excerpt { /** * Replaces the meta boxes. * * @return void */ public ...


14

You can use get_current_screen to determine this. $screen = get_current_screen(); if ( $screen->parent_base == 'edit' ) { echo 'edit screen'; } I don't know if I exactly would say this is always better, it depends on what's needed, but it's probably the way I'd do it. The big benefit with this method is that you get access to more information and ...


13

It's always a good idea to look at Wordpress Codex before asking. TinyMCE Custom Styles <?php // Insert 'styleselect' into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } // Use 'mce_buttons' for button row #1, mce_buttons_3' for button row #3 add_filter('mce_buttons_2', '...


11

The best way to do this is by adding 'user_can_richedit' filter, like so: add_filter( 'user_can_richedit', 'patrick_user_can_richedit'); function patrick_user_can_richedit($c) { global $post_type; if ('page' == $post_type) return false; return $c; } Hope it's useful ;)


11

On a free and publicly available theme, yes, you can! If you built the theme yourself, yes, you can! If the theme is under a GPL license or completely public domain, yes, you can! But If you're a client of a developer who has built the theme for you however it may not be so simple. It may be in your contract that it be put there, and you should have ...


10

There is a hook for that: 'mce_css'. It is called in _WP_Editors::editor_settings() and you get all loaded stylesheets comma separated as the first and only parameter. Now it is easy: Use the global variable $editor_styles (here are your theme’s and parent theme’s editor stylesheets stored already), add the time of the file’s last modification as a ...


10

new hooks for the add/edit post screen: edit_form_after_title add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' ); function myprefix_edit_form_after_title() { echo '<h2>This is edit_form_after_title!</h2>'; }


10

The answer suggested by GavinR is correct. You don't need to install the suggested plug-in, though. Just add this mini plugin and you're set: <?php defined( 'ABSPATH' ) OR exit; /* Plugin Name: TinyMCE break instead of paragraph */ function mytheme_tinymce_settings( $tinymce_init_settings ) { $tinymce_init_settings['forced_root_block'] = false; ...


9

Here is a basic solutions for updating a post/page. I added a quick demo of custom meta fields. This is pretty basic, but will point you in the direction of plugin-less editing of posts on the front-end. This isn't super flexible, but you can add whatever you need to it. Add this code into your loop: <form id="post" class="post-edit front-end-form" ...


9

I use Advanced Custom Fields for lots of front end post editing with meta boxes. ACF allows you to build lots of advanced meta box fields and adds them automatically to the back end post panel. But there is a front end function as well. This method is completely free. The only way it costs anything is if you want to use any of their more complex field type ...


9

I couldn't get toscho's answer to work for the current version of WordPress (4.7.2), and that seems to be because the TinyMCE init array has a cache_suffix set to 'wp-mce-' . $tinymce_version. So instead, you can just overwrite that with the tiny_mce_before_init filter, like so: function wpse33318_tiny_mce_before_init( $mce_init ) { $mce_init['...


9

There is not a way to do this without modifying the core. You should see .php files that are in subdirectories, but you won't see anything above the root theme directory for .css files, and you won't see any JavaScript files. If you take a look at wp-admin/theme-editor.php, the relevant lines are... <?php $allowed_files = $theme->get_files( 'php', ...


8

You don't want to edit core WordPress code. You don't need to edit core WordPress code to do what you need to implement. First, you need to study the WordPress templating (i.e. Theme) functionality. Then, you need to study Plugins and the WordPress Hooks API, including its Action Hooks and its Filter Hooks. To do what you're describing, you definitely don'...


8

If it's getting too hard and complicated, you can simply add new buttons by using jQuery. Simply clone an existing or create a new button, and append it to the editor's toolbar. You can wrap the javascript with a php function, and run it in the admin footer or something. Or you can use the edButton function. Here is a dirty and fast written example for ...


8

Use add_editor_style e.g.: functions.php add_editor_style('custom-editor-style.css'); http://codex.wordpress.org/Function_Reference/add_editor_style


8

If I understand well, user having a special role in your site should: Be able to edit own posts in all statuses but 'publish' and not be able to publish them, just send for revision Be able to edit others posts only when pending, but not be able to publish them, just send for revision Never be able to delete other posts, no matter the status If so, it ...


8

I was curious about this and checked the Codex on keyboard shortcuts, but didn't find it mentioned there. I searched and found out that this seems to be already solved, e.g. here and here. I haven't tested out these other plugins so I'm not sure how they solve it, but I decided to take on the challenge and see how this could be solved ;-) So here's my ...


7

There are a few functions that come in handy here: unstick_post - Unstick a post stick_post - Stick a post is_sticky - Figure out if a post is sticky With those three in mind, all we need to do is stick them together with some admin menu bar glue. First off, let's wrap everything in a class for fun and profit. This class will have some constants that we'...


7

You could do like this: function image_tag_class($class) { $class .= ' my-custom-class'; return $class; } add_filter('get_image_tag_class', 'image_tag_class' ); in case you wanna know more about actions and hooks. Difference Between Filter and Action Hooks? add_filter add_action


7

I was hunting for a way to do this, and no-one seems to mention the wp_editor_settings filter. This worked for me: function my_editor_settings($settings) { $settings['quicktags'] = false; return $settings; } add_filter('wp_editor_settings', 'my_editor_settings');


7

When registering your taxonomy you can pass an argument called capabilities. Simply passing capabiities that only admins and editors have. $args = array( 'capabilities' => array( 'manage_options', 'edit_posts' ) ); register_taxonomy( 'foobar', 'post', $args ); https://codex.wordpress.org/Roles_and_Capabilities#Editor


7

There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is not there (Good Thing) Consider this example and assume that we are using it on front-end in footer. First enqueue the essential style and scripts. function ...


7

Whilst this doesn't show a warning as you are asking for, you could always hide the "add new" link using the admin_head action: function yourprefix_admin_head() { echo '<style> #language-add-toggle { display: none; } </style>'; } add_action('admin_head', 'yourprefix_admin_head'); The element ID is the taxonomy name followed by ...


6

For me, the button became available once I clicked and dragged the mouse cursor over part of the image to select an area to crop.


6

Thanks for the hint Bainternet, indeed this is very easy to implement with jQuery. Example (the four meta boxes are closed for clarity) : Here's what I did : var $j = jQuery.noConflict(); $j(document).ready(function() { $j("#side-sortables").append('<div id="container_div" class="postbox meta-box-sortables ui-sortable"><div class="handlediv" ...


Only top voted, non community-wiki answers of a minimum length are eligible