Translation with gettext

18. August 2020

function this_translations( $translation, $text, $domain ) {
	if ( 'woocommerce' === $domain ) {
		switch ( $translation ) {
			case 'Includes':
				$translation = 'Inkluderet';
				break;
			case 'MVA':
				$translation = 'moms';
				break;
		}
	}

	return $translation;
}
add_filter( 'gettext', 'this_translations', 10, 3 );
Replace ‘Dismiss’ with an X in Woo store notice

2. April 2020

function twstudio_demo_store_filter($text) {

	$text = str_replace(array('<p class="woocommerce-store-notice demo_store">', '</p>', 'Dismiss'), array('<div class="woo-notice-container"><p class="woocommerce-store-notice demo_store">', '</p></div>', 'X'), $text);
	return $text;
}
add_filter('woocommerce_demo_store', 'twstudio_demo_store_filter', 10, 1);
Remove Uncategorized from widget

20. March 2020

function remove_uncategorized_category( $terms, $taxonomy, $query_vars, $term_query ) {
if ( is_admin() )
return $terms; if ( $taxonomy[0] == 'product_cat' ) {
foreach ( $terms as $k => $term ) {
if ( $term->term_id == get_option( 'default_product_cat' ) ) {
unset( $terms[$k] );
}
}
} return $terms;
}
add_filter( 'get_terms', 'remove_uncategorized_category', 10, 4 );
Simple function based on queried page

12. February 2020

<?php
$term = get_queried_object();
$type = $term->post_type;
if ( $type === 'event' ) {
	if ( has_post_thumbnail() ) {
		$size = apply_filters( 'twstudio_default_thumbnail_size', 'large' );
		the_post_thumbnail( $size, array( 'class' => 'featured-image' ) );
	}
}
?>
Check if browser is IE

22. May 2019

Replace a text string in PHP/WordPress

8. March 2019

Check if user is logged in and do something

10. July 2018

 

Get site url

8. July 2018

Gives you the sites url..

<?php echo get_site_url(); ?>

Gives you a specific page:

Gives you an image:

Set the Thumbnail size

15. May 2018

This goes into your theme setup function in functions.php

(To register new sizes: https://developer.wordpress.org/reference/functions/add_image_size/.)

Hook example

8. May 2018

Add Taxonomies for media gallery

6. May 2018

Goes into functions.php

Ny first PHP code

24. April 2018

 

PHP/WP nice to know things

20. April 2018