Add type to enqueued script inside plugin

There’s a filter: script_loader_tag. add_filter( ‘script_loader_tag’, ‘wpse397773_change_script_tags’, 10, 3 ); function wpse397773_change_script_tags( $tag, $handle, $src ) { $tag = ‘<script type=”text/plain” src=”‘ . $src . ‘” id=”‘ . $handle . ‘-js”></script>’; return $tag; } This should change all the <script> tags in the page (assuming they’re properly enqueued) to <script type=”text/plain”>. Update: To only change … Read more

Can the uniqueness of the plugin file/plugin slug and version number be trusted?

Not really. There’s no 100% reliable way to guarantee that wordpress-seo/wp-seo.php on one site is the same plugin as wordpress-seo/wp-seo.php on another site, short of hashing the files, as you mentioned. It is highly unlikely that they are different plugins, but since there is no centralised system for registering unique plugin names, it cannot be … Read more

How to Define Multiple List Tables in a Single Submenu

You don’t. WP_List_Table and the following features were all built on the assumption of there only being a single table on the page: choosing columns via screen options pagination column sorting search/filtering bulk actions At best, you could use the code from the official developer docs to print a second table, but then you’ll run … Read more

Adding Plugin Assets to Header

I finally done like this: $form_styles_header = [ “1” => “forms/vendor/bootstrap/css/bootstrap.min.css”, “2” => “forms/fonts/font-awesome-4.7.0/css/font-awesome.min.css”, “3” => “forms/vendor/animate/animate.css”, “4” => “forms/vendor/css-hamburgers/hamburgers.min.css”, “5” => “forms/vendor/animsition/css/animsition.min.css”, “6” => “forms/vendor/select2/select2.min.css”, “7” => “forms/vendor/daterangepicker/daterangepicker.css”, “8” => “forms/css/util.css”, “9” => “forms/css/main.css”, “10” => “table/css/table-styles.css” ]; foreach ($form_styles_header as $no=>$form_style) { wp_enqueue_style(‘du_form_style’.$no, $d_utility_url.”/assets/”.$form_style); } where $d_utility_url is the path to my plugin. … Read more

How to use template_include hook with form submission?

It turns out that $wp->query_vars[“post_type”] contains the data I need, regardless of whether the request method is GET or POST. namespace mynamespace; class MyPlugin { public static function template_include($template) { global $wp; if ($wp->query_vars[“post_type”] == ‘thing’) { return plugin_dir_path( __FILE__ ) . ‘templates/thing.php’; } return $template; } } add_filter(‘template_include’, ‘\mynamespace\MyPlugin::template_include’); Also, it appears that the … Read more

plugins not working in custom theme

Your theme does not contain a main post loop, so there is no place for the plugin to do its work if ( have_posts() ) { while ( have_posts() ) { the_post(); // // Post Content here // the_content(); } // end while } // end if https://codex.wordpress.org/The_Loop

Gutenberg Blocks – Cannot retrieve block saved attributes in edit post

The block validation failed because the editor did not parse the attributes from all images (in the saved post content), and it’s because your save function is returning only one .slider-item div containing multiple img tags, like so: <div class=”slider-item”> <img src=”…” data-id=”123″ /> <img src=”…” data-id=”456″ /> … </div> And what should actually be … Read more