diff --git src/wp-includes/class.wp-scripts.php src/wp-includes/class.wp-scripts.php
index 52c6824..6278c5a 100644
--- src/wp-includes/class.wp-scripts.php
+++ src/wp-includes/class.wp-scripts.php
@@ -145,6 +145,9 @@ class WP_Scripts extends WP_Dependencies {
 			 * @param string $handle Script handle.
 			 */
 			$srce = apply_filters( 'script_loader_src', $src, $handle );
+
+			$this->print_code .= $this->print_inline_script( $handle, 'before', false );
+
 			if ( $this->in_default_dir( $srce ) && ! $conditional ) {
 				$this->print_code .= $this->print_extra_script( $handle, false );
 				$this->concat .= "$handle,";
@@ -154,6 +157,8 @@ class WP_Scripts extends WP_Dependencies {
 				$this->ext_handles .= "$handle,";
 				$this->ext_version .= "$handle$ver";
 			}
+
+			$this->print_code .= $this->print_inline_script( $handle, 'after', false );
 		}
 
 		$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
@@ -194,10 +199,77 @@ class WP_Scripts extends WP_Dependencies {
 		 */
 		$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
 
+		$before_handle = $this->print_inline_script( $handle, 'before', false );
+		$after_handle  = $this->print_inline_script( $handle, 'after', false );
+
 		if ( $this->do_concat ) {
+
+			if ( $before_handle ) {
+				$this->print_html .= sprintf( "<script id='%s-inline-js' type='text/javascript'>\n%s\n</script>\n", esc_attr( $handle ), $before_handle );
+			}
+
 			$this->print_html .= $tag;
+
+			if ( $after_handle ) {
+				$this->print_html .= sprintf( "<script id='%s-inline-js' type='text/javascript'>\n%s\n</script>\n", esc_attr( $handle ), $after_handle );
+			}
 		} else {
+			$this->print_inline_script( $handle, 'before' );
 			echo $tag;
+			$this->print_inline_script( $handle, 'after' );
+		}
+
+		return true;
+	}
+
+	/**
+	 * Add extra code to a registered script.
+	 *
+	 * @since 4.5.0
+	 *
+	 * @param string $handle   Name of the script to add the inline script to. Must be lowercase.
+	 * @param string $data     String containing the javascript to be added.
+	 * @param string $position Optional. Whether to add the inline script before the handle
+	 *                         or after. Default 'after'.
+	 *
+	 * @return bool True on success, false on failure.
+	 */
+	public function add_inline_script( $handle, $data, $position = 'after' ) {
+		if ( ! $data ) {
+			return false;
+		}
+
+		if ( 'after' !== $position ) {
+			$position = 'before';
+		}
+
+		$script   = (array) $this->get_data( $handle, $position );
+		$script[] = $data;
+
+		return $this->add_data( $handle, $position, $script );
+	}
+
+	/**
+	 * Print inline scripts registered for a specific handle.
+	 *
+	 * @param string $handle   Name of the script to add the inline script to. Must be lowercase.
+	 * @param string $position Optional. Whether to add the inline script before the handle
+	 *                         or after. Default 'after'.
+	 * @param bool $echo       Optional. Whether to echo the script instead of just returning it.
+	 *                         Default true.
+	 * @return bool True on success, false otherwise.
+	 */
+	public function print_inline_script( $handle, $position = 'after', $echo = true ) {
+		$output = $this->get_data( $handle, $position );
+
+		if ( empty( $output ) ) {
+			return false;
+		}
+
+		$output = trim( implode( "\n", $output ), "\n" );
+
+		if ( $echo ) {
+			printf( "<script id='%s-inline-js-%s' type='text/javascript'>\n%s\n</script>\n", esc_attr( $handle ), $position, $output );
 		}
 
 		return true;
diff --git src/wp-includes/functions.wp-scripts.php src/wp-includes/functions.wp-scripts.php
index a3ac7e6..4d6b732 100644
--- src/wp-includes/functions.wp-scripts.php
+++ src/wp-includes/functions.wp-scripts.php
@@ -86,6 +86,36 @@ function wp_print_scripts( $handles = false ) {
 }
 
 /**
+ * Add extra code to a registered script.
+ *
+ * Code will only be added if the script in already in the queue.
+ * Accepts a string $data containing the Code. If two or more code blocks
+ * are added to the same script $handle, they will be printed in the order
+ * they were added, i.e. the latter added code can redeclare the previous.
+ *
+ * @since 4.5.0
+ *
+ * @see WP_Scripts::add_inline_script()
+ *
+ * @param string $handle   Name of the script to add the inline script to. Must be lowercase.
+ * @param string $data     String containing the javascript to be added.
+ * @param string $position Optional. Whether to add the inline script before the handle
+ *                         or after. Default 'after'.
+ * @return bool True on success, false on failure.
+ */
+function wp_add_inline_script( $handle, $data, $position = 'after' ) {
+	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
+
+	if ( false !== stripos( $data, '</script>' ) ) {
+		_doing_it_wrong( __FUNCTION__, __( 'Do not pass script tags to wp_add_inline_script().' ), '4.1.3' );
+		$data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
+	}
+
+	return wp_scripts()->add_inline_script( $handle, $data, $position );
+}
+
+
+/**
  * Register a new script.
  *
  * Registers a script to be linked later using the wp_enqueue_script() function.
diff --git tests/phpunit/tests/dependencies/scripts.php tests/phpunit/tests/dependencies/scripts.php
index 73680df..0fec6a3 100644
--- tests/phpunit/tests/dependencies/scripts.php
+++ tests/phpunit/tests/dependencies/scripts.php
@@ -166,4 +166,78 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
         $this->assertFalse( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
     }
 
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_returns_bool() {
+		$this->assertFalse( wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ) );
+		wp_enqueue_script( 'test-example', 'example.com', array(), null );
+		$this->assertTrue( wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ) );
+	}
+
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_unknown_handle() {
+		$this->assertFalse( wp_add_inline_script( 'test-invalid', 'console.log("before");', 'before' ) );
+		$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
+	}
+
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_before() {
+		wp_enqueue_script( 'test-example', 'example.com', array(), null );
+		wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
+
+		$expected = "<script id='test-example-inline-js-before' type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
+		$expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
+
+		$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+	}
+
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_after() {
+		wp_enqueue_script( 'test-example', 'example.com', array(), null );
+		wp_add_inline_script( 'test-example', 'console.log("after");' );
+
+		$expected = "<script type='text/javascript' src='http://example.com'></script>\n";
+		$expected .= "<script id='test-example-inline-js-after' type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
+
+		$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+	}
+
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_before_and_after() {
+		wp_enqueue_script( 'test-example', 'example.com', array(), null );
+		wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
+		wp_add_inline_script( 'test-example', 'console.log("after");' );
+
+		$expected = "<script id='test-example-inline-js-before' type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
+		$expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
+		$expected .= "<script id='test-example-inline-js-after' type='text/javascript'>\nconsole.log(\"after\");\n</script>\n";
+
+		$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+	}
+
+	/**
+	 * @ticket 14853
+	 */
+	function test_wp_add_inline_script_multiple() {
+		wp_enqueue_script( 'test-example', 'example.com', array(), null );
+		wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
+		wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
+		wp_add_inline_script( 'test-example', 'console.log("after");' );
+		wp_add_inline_script( 'test-example', 'console.log("after");' );
+
+		$expected = "<script id='test-example-inline-js-before' type='text/javascript'>\nconsole.log(\"before\");\nconsole.log(\"before\");\n</script>\n";
+		$expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
+		$expected .= "<script id='test-example-inline-js-after' type='text/javascript'>\nconsole.log(\"after\");\nconsole.log(\"after\");\n</script>\n";
+
+		$this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+	}
 }
