Tag Archives: Wordpress

Combine+Minify styles of parent theme and add as inline-style in wordpress

In a recent project, one of my tasks was to optimize and minify the styles included by the child-theme by combining and minify the styles of the parent theme into one file or include as custom inline style. While working on the task, I ended up reading multiple resources to and writing the function below. The function first fetches all the styles that are being included on page, and then for the handles belonging to the parent theme, the script then concatenates the scripts and then minifies by using preg_replace(). The generate combined CSS is stored in a database table and updated every 24 hours(triggered on page load). It then de-registers the style handles we have combined and includes the custom style as an inline style.

Read more

Check WooCommerce coupon via Ajax

Here is how a WooCommerce coupon code can be checked for validity. The code below allows us to check WooCommerce coupon against the database. This is done using the inbuilt WC_Coupon class provided by WooCommerce.

Read more

WordPress user creation via custom PHP function

In the code below, we are registering the user via Ajax request and receiving a JSON reply from the script. The code also checks and validates the sent email address against the user information already in the database. You can place the code in your theme’s functions file and send the form via POST to admin-ajax.

Read more

Override Contact Form 7 Messages and display in Modal or Alert

/* Validation Events for changing response CSS classes */
document.addEventListener( ‘wpcf7invalid’, contactform7replace );
document.addEventListener( ‘wpcf7spam’, contactform7replace );
document.addEventListener( ‘wpcf7mailfailed’, contactform7replace );
document.addEventListener( ‘wpcf7mailsent’, contactform7replace );

function contactform7replace(){
modal = jQuery(‘#Modal’);
msgcontainer = jQuery(“.wpcf7-response-output”);


modal.find(‘.modal-body’).html( ‘Please wait…’ );
modal.find(‘.modal-footer, .modal-title’).hide();
msg = msgcontainer.html();
modal.find(‘.modal-body’).html( msg );