How to automatically apply woocommerce product title to all product images alt tags?

This is what you need, taken from – https://stackoverflow.com/questions/27087772/how-can-i-change-meta-alt-and-title-in-catalog-thumbnail-product-thumbnail add_filter(‘wp_get_attachment_image_attributes’, ‘change_attachement_image_attributes’, 20, 2); function change_attachement_image_attributes( $attr, $attachment ){ // Get post parent $parent = get_post_field( ‘post_parent’, $attachment); // Get post type to check if it’s product $type = get_post_field( ‘post_type’, $parent); if( $type != ‘product’ ){ return $attr; } /// Get title $title = get_post_field( … Read more

Fatal error: Call to undefined function post_exists()

The files in wp-admin are only loaded when you’re in the admin area… when you’re looking at pages or posts those functions aren’t loaded. In that case you’d need to require the file first, so you’d want to do something like this in your function: if ( ! is_admin() ) { require_once( ABSPATH . ‘wp-admin/includes/post.php’ … Read more

How to call a PHP function from Javascript in WordPress

Here’s an example: Use this sample JavaScript code: jQuery(document).on(‘click’, ‘.some-element’, function(e){ var ipc = jQuery(this).data(‘collection-id’); jQuery(‘.some-other-element’).show(); jQuery.ajax({ method: ‘post’, url: ipAjaxVar.ajaxurl, data: { collection_id: ipc, action: ‘my_function’, } }).done(function(msg) { // Do something when done }); e.preventDefault(); }); PHP (include the function in your plugin, do not use a separate file): // Include the JavaScript … Read more