Skip to content

Instantly share code, notes, and snippets.

View webzunft's full-sized avatar

Thomas Maier webzunft

View GitHub Profile
@webzunft
webzunft / advanced-ads-company-category.php
Last active March 5, 2019 10:30
Add a company taxonomy to ads managed by the Advanced Ads plugin.
<?php
/**
* Advanced Ads – Company Category
*
* @wordpress-plugin
* Plugin Name: Advanced Ads – Company Category
* Plugin URI: https://wpadvancedads.com
* Description: Add a Company category to ads so that you can group them.
* Version: 0.1
* Author: Thomas Maier
@webzunft
webzunft / css
Created September 17, 2018 09:17
Reserve ad space with a ratio
/** this code allows to reserve ad space with a ratio, e.g., when width is 100% and height needs to be adjusted dynamically
https://www.w3schools.com/howto/howto_css_aspect_ratio.asp
"top-banner-ads" is the class of the main container, in Advanced Ads derived from the placement name
**/
.top-banner-ads {
width: 100%;
height: auto;
padding-top: 12.4%; /* 728:90 ratio */
position: relative;
}
@webzunft
webzunft / log.php
Last active December 18, 2015 12:09
function to log events for themes in WordPress functions.php
/* LOG FUNCTION */
function log( $input ){
$time = date('d-m-Y H:i T');
$file = get_template_directory() . '/log.txt';
$handle = fopen($file, 'a');
$data = '--------------- ' . $time."--------------- \r\n".$input."\r\n";
fwrite($handle, $data);
fclose($handle);
}
@webzunft
webzunft / gist:5598039
Created May 17, 2013 09:35
Code to allow to create and update a user in WordPress without an e-mail address. It simply removes the error message. This code was written to be used in a plugin written as a class
public function __construct () {
// other code...
add_action( 'user_profile_update_errors', array( $this, 'remove_empty_email_error' ));
}
function remove_empty_email_error( $arg ) {
if ( !empty( $arg->errors['empty_email'] ) ) unset( $arg->errors['empty_email'] );
}
@webzunft
webzunft / functions.php
Created February 18, 2014 19:54
Sample code for an adblocker check based on BlockAlyzer for WordPress
function adblock_alert(){
?><script type="text/javascript">
jQuery(document).ready(function($) {
setTimeout(function(){
if ( ba_blocked == true ) alert("You are using adblock.");
},200)
});
</script><?php
}
add_action('wp_footer', 'adblock_alert');
@webzunft
webzunft / body section
Created January 29, 2014 17:04
asynchronous Google DFP for Publishers Tag code with explanations
<!-- the id must match the id defined in the slot -->
<!-- style attribut is optional, but useful to prevent to shift layout after ad is loaded -->
<div id="banner1" style="width:300px; height:250px;">
<script type="text/javascript">
// id 'banner1' is used here, again
googletag.cmd.push(function() { googletag.display('banner1'); });
</script>
</div>