Skip to content

Instantly share code, notes, and snippets.

View cubehrends's full-sized avatar
🏠
Working from home

Christian Behrends cubehrends

🏠
Working from home
View GitHub Profile
@cubehrends
cubehrends / functions.php
Last active April 17, 2021 17:44
Redirect Folder
<?php
function wdt_redirect_brand() {
$uri = $_SERVER['REQUEST_URI'];
if( !is_user_logged_in() ) {
if ( strpos( $uri, '/brand/') === 0 ) {
$r301 = str_replace( '/brand/', '/marke/', $uri );
UPDATE wp_postmeta AS sku
JOIN (SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_ts_gtin') AS gtin USING (post_id)
SET sku.meta_value = gtin.meta_value
WHERE sku.meta_key = '_sku'
<script>
(function( $ ) {
$( '.et_pb_toggle' ).hover(function() {
$( this ).children( 'h5' ).trigger( 'click' );
});
})( jQuery );
</script>
<?php
add_shortcode( 'techtable', function () {
$techdata = get_post_meta( get_the_ID(), 'technische_daten', true );
if( $techdata ) {
$out = '<table>';
$lines = explode( "\n", $techdata );
foreach( $lines as $line ){
$out .= '<tr>';
@cubehrends
cubehrends / functions.php
Last active June 7, 2020 13:10
301 Moved Permanently via WordPress Child Theme functions.php
<?php
function redirect_to_url() {
switch ( $_SERVER['REQUEST_URI'] ) {
case '/an-old-uri/':
$redirect_to = '/the-new-uri/';
break;
case '/another-old-uri/':
$redirect_to = '/another-new-uri/';
break;
<?php
/* Shortcode to Display Post Tags in UnorderedList /w specific CSS-Class and Link to Archive
=============================================================== */
function display_tags( $atts, $content = null ) {
$post_tags = get_the_tags();
if ( $post_tags ) {
$html = '<ul class="tag-list">';
foreach( $post_tags as $tag ) {
$html .= '<li><a class="' . $tag->slug . '" href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a></li>';
<?php
/* adding og:image for Facebook shares
=============================================================== */
add_action( 'wp_head', function(){
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
if ($featured_image) {
echo '<meta property="og:image" content="'.$featured_image[0].'">';
}
@cubehrends
cubehrends / functions.php
Last active June 17, 2019 12:30
Addin Brand Name to Item Title in WooCommerce Product Lists
<?php
add_action('woocommerce_shop_loop_item_title','brands_to_item_title', 11);
function brands_to_item_title( ) {
$brands = wp_get_post_terms( get_the_ID(), 'product_brand' );
if ( count( $brands ) > 0 ) {
foreach( $brands as $brand )
echo '<span class="brand-name">' . $brand->name . '</span>';
}
@cubehrends
cubehrends / functions.php
Last active June 12, 2019 15:50
Adding Brand Archive Link to Single Product Summary in WooCommerce
<?php
add_action( 'woocommerce_single_product_summary', 'add_brand_to_single_product_summary', 6 );
function add_brand_to_single_product_summary() {
global $post;
if ( ! $post_id && ! $post )
return;
if ( ! $post_id )
$post_id = $post->ID;
@cubehrends
cubehrends / header.php
Last active November 7, 2018 08:49
301 Moved Permanently vie PHP header
<?php
function redirectTo( $location ) {
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: ' . $location );
header( 'Connection: close' );
}
switch ( $_SERVER['REQUEST_URI'] ) {
case '/post/an-uri-on-old-domain':
redirectTo( 'https://new-domain.com/a-new-uri/' );
break;