How to Use Custom Meta Field Instead of CPT Title in Post URL

You have to use a wp_update_post function and update the required fields based on available fields in WP_Post class. add_action( ‘save_post’, ‘wpse75679_save_post’ ); function wpse75679_save_post( $post_id ) { if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; // verify post is not a revision if ( ! wp_is_post_revision( $post_id ) ) { // unhook this function … Read more

get_page_template_slug returns incorrect path

I just checked what the function you called does and it just retrieves the _wp_page_template value from the wp_postmeta table of WordPress. So probably the structure of your theme is not right, some rewrites are active, or something else (e.g. plug-in) altered this database table. You could check that the theme root directory is indeed … Read more

How to find and remove unnecessary theme scripts? [closed]

You should locate all wp_register_script instances (they can be incuded in core, plugin, theme, anywhere) and in your functions.php you can deregister them add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ ); function my_scripts_method() { // if you want to exclude built-in jQuery wp_deregister_script(‘jquery’); } All scripts that can be enqueued by WordPress are listed (there are handles of each) … Read more

Which cache is kicking

You could change the file version each time the file gets updated. To do this, go to your functions.php file and find where the style-sheet is being enqueued (or registered) – it will look something like: wp_enqueue_style( ‘theme-style’, get_template_directory_uri() . ‘/style.css’ ); and change it to: wp_enqueue_style( ‘theme-style’, get_template_directory_uri() . ‘/style.css’, array(), filemtime( get_template_directory_uri() . … Read more

How to safely return the HTML?

Ok, so this is why it’s important to post the actual code that’s giving you problems. There is nothing wrong with this, which is all you had originally: return ‘<button type=”button” class=”btn btn-success”>Open Now</button>’; If that was the error, you could ignore it. This, on the other hand, does need to be escaped: $wppl_open = … Read more

How to enqueue a script which is type module without using script_loader_tag filter?

Lets try this: function slider_script () { wp_enqueue_script( ‘slider-js’, get_stylesheet_directory_uri() . ‘/src/js/slider.js’, array(), time(), true ); } function add_type_attribute( $tag, $handle, $src ) { if ( ‘slider-js’ !== $handle ) { return $tag; } $tag = preg_replace(“/(.*)(><\/script>)/”, ‘$1 type=”module”$2’, $tag); return $tag; } add_action(‘wp_enqueue_scripts’, ‘slider_script’); add_filter( ‘script_loader_tag’, ‘add_type_attribute’, 10, 3 );

Localize script not working in ajax

Running the localize script after the script.min.js file If that is the script you’re trying to localize, which you enqueued using the script handle mild-scripts, then you also need to use that as the script handle when calling wp_localize_script(). I.e. wp_localize_script( ‘mild-scripts’, // script handle ‘WPURLS’, // JS object name array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ … Read more