-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbo-drive.php
45 lines (39 loc) · 1.33 KB
/
turbo-drive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Plugin Name: Turbo Drive
* Plugin URI: https://wordpress.org/plugins/td-turbo-drive
* Description: Integrate Hotwired Turbo with WordPress, no page reload, no jQuery, no bullshit.
* Author: Romain Herault
* Author URI: https://rherault.dev
* Text Domain: turbo-drive
* Domain Path: /languages
* Version: 0.3.2
*
* @package Turbo_Drive
*/
add_action('wp_enqueue_scripts', function () {
wp_enqueue_script('turbo-drive', plugins_url('/dist/main.js', __FILE__));
}, 10);
add_action('admin_head', function () {
echo '<meta name="turbo-visit-control" content="reload">';
}, 10);
add_filter('script_loader_tag', function ($script_tag) {
if (is_admin()) {
return $script_tag;
}
global $current_screen;
if ($current_screen instanceof \WP_Screen && $current_screen->is_block_editor()) {
return $script_tag;
}
return str_replace(' src', ' data-turbo-track="reload" src', $script_tag);
}, 10, 1);
add_filter('style_loader_tag', function ($style_tag) {
if (is_admin()) {
return $style_tag;
}
global $current_screen;
if ($current_screen instanceof \WP_Screen && $current_screen->is_block_editor()) {
return $style_tag;
}
return str_replace(' href', ' data-turbo-track="reload" href', $style_tag);
}, 10, 1);