Loading newest dependency javascript module file in functions.php

The problem Import statement like: import { export1 } from “./module-name.js”; is called static import declaration. Dynamic query string (to force load the latest file) cannot be used in static import declarations. So, to solve this problem, you’ll have to choose one of the following four options: Remove export and import statements from all the … Read more

delete_term is not working properly with add_action()

AFAIK, slug is unique. So $post_cat_term = get_term_by( ‘slug’, $deleted_term->slug, ‘category’ ); shouldn’t return anything. Instead, you may try name. Also, delete_term callback gets 5 parameters, so it’s better to adjust that accordingly. See if the following works: function delete_similar_term( $term_id, $tt_id, $taxonomy, $deleted_term, $object_ids ) { if( $deleted_term->taxonomy === ‘movies_category’ ) { $post_cat_term = … Read more

Auto updating JavaScript dependancy in functions.php

If I understood your question correctly, you have two JavaScript files: ads.js and banner.js. You want the site to load the updated version of both of these files, whenever any of these files are changed. If this understanding is correct, then you may do the following: function my_custom_theme_scripts() { $ads_version = filemtime( get_stylesheet_directory() . ‘/js/ads.js’ … Read more

How to enqueue Bootstrap 4.6 js & css from local files

This answer was given on the main StackOverflow platform wp_enqueue_script( ‘bootstrap-js’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array( ‘jquery’ ), ‘4.6.0’, true); wp_enqueue_style( ‘bootstrap-css’, get_template_directory_uri() . ‘/css/bootstrap.min.css’, array(), ‘4.6.0’, ‘all’ ); The supplied code has been tested and works as expected

How to overwrite image if it already exists – WordPress, Gravity form

These lines of code and can help you to overwrite image $attachment_id = get_post_thumbnail_id($post_id); wp_delete_attachment($attachment_id, true); if(isset($file) && !empty($file) ){ $upload_overrides = array(‘test_form’=> false); $movefile = wp_handle_upload($file, $upload_overrides); $filename = basename( $movefile[‘url’] ); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( ‘guid’ => $wp_upload_dir[‘url’] . “https://wordpress.stackexchange.com/” . $filename, ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, … Read more

How can I modify or filter this variable in an existing class? (Mai Theme)

Sometimes it takes asking a question to find out the answer. function my_attachment_grid() { $args = [ ‘post_type’ => ‘attachment’, ]; add_filter( ‘post_query_args’, ‘my_filter’, 10, 1 ); do_grid( ‘post’, $args ); } function my_filter( $args ) { $defaults = [‘post_status’=>’inherit’]; $args = array_merge( $args, $defaults ); return $args; }