fbpx

How to separate images & iaragraphs

Stop images getting wrapped up in paragraph tags when they get dumped out with
simply add this on functions.php

// Stop images getting wrapped up in p tags when they get dumped out with the_content() for easier theme styling
function wpfme_remove_img_ptags($content){
	return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'wpfme_remove_img_ptags');

How to Remove width & height attributes from images in posts

Looking to remove the width and height attributes from images in your posts? Is this because you are using a responsive wordpress theme. Just add this snippet to the functions.php of your wordpress theme and all of the width and height attributes will be removed from your images.

add_filter( 'post_thumbnail_html', 'remove_wps_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_wps_width_attribute', 10 );
 
function remove_wps_width_attribute( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}

How to Display theme information with wp_get_theme

Adding this snippet to your wordpress theme will let you display data from your theme file. name, title, uri, description, authorURI, template, version, status, tags, author. We have updated this snippet to coincide with the most recent changes to wordpress.

<?php
$theme_data = wp_get_theme();
echo $theme_data->get( 'Name' );        // Theme name as given in style.css
echo $theme_data->get( 'ThemeURI' );
echo $theme_data->get( 'Description' );
echo $theme_data->get( 'Author' );
echo $theme_data->get( 'AuthorURI' );
echo $theme_data->get( 'Version' );
echo $theme_data->get( 'Template' );
echo $theme_data->get( 'Status' );
echo $theme_data->get( 'Tags' );
echo $theme_data->get( 'TextDomain' );
echo $theme_data->get( 'DomainPath' );
?>

How to Remove <p> and <br/> from Contact Form 7

Contact form 7 is a great tool but sometimes it adds a little extra HTML that you might want to get rid off within your page, posts. Adding this snippet to your wp-config will remove all of the extra and from your forms. Add the code on functions.php

define('WPCF7_AUTOP', false );

WOOCOMMERCE : Add a custom currency / symbol

Add this on your functions.php

add_filter( 'woocommerce_currencies', 'add_my_currency' );
 
function add_my_currency( $currencies ) {
     $currencies['ABC'] = __( 'Currency name', 'woocommerce' );
     return $currencies;
}
 
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
 
function add_my_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'ABC': $currency_symbol = '$'; break;
     }
     return $currency_symbol;
}