Skip to content

Instantly share code, notes, and snippets.

@vdite
vdite / get_parameter_javascript.html
Created December 5, 2013 13:33
how to grab URL GET parameters with Javascript
<div class="content">
<p>Lorem Ipsum Anything</p>
<script type="text/javascript">
if(window.location.href.match(/arg=testA/)){
document.write('<button name="button">Click me</button>');
}elseif(window.location.href.match(/arg=TestB/)){
document.write('<button name="button">Click me now!</button>');
}else{
document.write('<button name="button">Show me</button>');
}
@vdite
vdite / log_arrays_to_file.php
Last active December 23, 2015 20:09
This is how to var_dump to a file with php
<?php
/** Thanks to Pascal Landau
** https://plus.google.com/105523642741376989823/posts
**/
$handle = fopen("path/log.log","a");
fwrite($handle, var_export($array_or_object, true));
fclose($handle);
?>
@vdite
vdite / gist:6509790
Created September 10, 2013 13:59
Breadcrumb für Wordpress ohne Plugin
/**
* Retrieve List of Breadcrubms without Rich-Snippets Option
* put this in your functions.php located in the templates folder
* call this with <?php echo write_breadcrumb(); ?> inside yout template
*/
function write_breadcrumb() {
$pid = $post->ID;
$trail = '<a href="/">Home</a>';
if (is_front_page()) {
@vdite
vdite / new_gist_file
Created September 9, 2013 10:06
manual loading Google Webfont
@font-face {
font-family: 'Fjalla One';
font-style: normal;
font-weight: 400;
src: local('Fjalla One'), local('FjallaOne-Regular'), url(http://themes.googleusercontent.com/static/fonts/fjallaone/
v1/rxxXUYj4oZ6Q5oDJFtEd6r3hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: normal;
@vdite
vdite / gist:6391520
Created August 30, 2013 16:13
replaces given string in a bunch of files inside an folder with php
<?php
foreach(glob('./*.html') as $filePath) {
$file_contents = file_get_contents($filePath);
$file_content_replace = preg_replace('windows','linux',$file_contents);
file_put_contents($filePath,$file_content_replace);
}
?>
@vdite
vdite / debug php in the browser console
Created July 7, 2013 11:43
best way to debug php in the browser console
<?php
/**
* Send debug code to the Javascript console
*/
function debug_to_console($data) {
if(is_array($data) || is_object($data))
{
echo("<script>
if(console.debug!="undefined"){
console.log('PHP: ".json_encode($data)."');
@vdite
vdite / Completely Remove RSS Feeds in WordPress
Created June 28, 2013 20:04
Completely Remove RSS Feeds in WordPress
<?php
// add this to yout functions.php file
// you may just want to kill all your RSS Feeds, wordpress does provide
remove_action('do_feed', 'disable_all_feeds', 1);
remove_action('do_feed_rdf', 'disable_all_feeds', 1);
remove_action('do_feed_rss', 'disable_all_feeds', 1);
remove_action('do_feed_rss2', 'disable_all_feeds', 1);
remove_action('do_feed_atom', 'disable_all_feeds', 1);
@vdite
vdite / jQuery: Collapse iframe if empty
Created June 28, 2013 09:55
Collapse iframe if empty with jQuery
// if you are using no caching headers in your iframe sources, so you 'll always get an "filled" iframe. This does kick your layout sometimes.
// this is how to coollapse such iframes:
if($("#iframeid").contents().find("p").length) {
$('#iframeid').css('display', 'none');
}
// this is how to kill all caches in the iframe source
// <head>
// <meta http-Equiv="Cache-Control" Content="no-cache">
@vdite
vdite / redirect old site to new domain
Created June 27, 2013 21:09
Redirect an old domain and all the old sites to a new domain
#this redirects all your old stuff to the main site of the new domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^old-domain.com [NC]
RewriteRule ^(.*)$ http://new-domain.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC]
RewriteRule ^(.*)$ http://new-domain.com/ [L,R=301]
#this redirects all your old stuff to the new domain, leaving all deep urls like before
RewriteEngine on
RewriteCond %{HTTP_HOST} ^old-domain.com [NC]
@vdite
vdite / Get all POST Variables from the array
Created June 19, 2013 19:48
PHP: howto automatically create variables with the same name as key in POST array
// One more cautios way of extracting all input fields at once is:
extract( $_POST, EXTR_OVERWRITE, "form_" );
// This way all your input variables will be called $form_foo and $form_bar at least.
// Avoid doing that in the global scope - not because global is evil, but because nobody ever cleans up there.
// http://goo.gl/3Q5RV
// Thanks to Sergej Müller @wpSEO
// you know this how you are doing:
$username=$_POST["username"];
$age=$_POST["age"];