Ask questions about WordPress courses

Editor scrolling on save in WordPress

WordPress has a good editor, in my opinion, this editor has obvious inconveniences.
Every time, when you save a message, editor scroll position will be on top again. If you want to keep writing a long post, it will take you a lot of time, until you find the old cursor position.

wp-editor-preserve-scroll-position - возврат позиции курсора после сохранения WordPress
To avoid this, I found a code snippet on the Internet, which I want to share with you.

', esc_attr( $position ) );
		// Print Javascript data
		add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_js' ), 55 ); // Print after Editor JS.
	}
	/**
	 * Extend TinyMCE config with a setup function
	 */
	public static function extend_tiny_mce( $init ) {
		if ( 'tinymce' == wp_default_editor() )
			$init['setup'] = 'rich_scroll';
		return $init;
	}
	/**
	 * Returns redirect url with query arg for scroll position
	 */
	public static function add_query_arg( $location ) {
		if ( ! empty( $_POST['scrollto'] ) )
			$location = add_query_arg( 'scrollto', (int) $_POST['scrollto'], $location );
		return $location;
	}
	/**
	 * Prints Javascript data
	 */
	public static function print_js() {
		?>  

At the end, as always, some delicious. I suggest a plugin with a similar action Preserve Editor Scroll Position.

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal