Skip to content

Instantly share code, notes, and snippets.

@matthiaspabst
matthiaspabst / gravityforms-antispam.php
Created October 24, 2019 09:36
Gravity Forms Antispam
<?php
/**
* Gravity Forms Antispam
* Check if field has a predefined value
* https://docs.gravityforms.com/gform_field_validation/#1-number-field-validation
*/
function gf_antispam( $result, $value, $form, $field ) {
if ( $result['is_valid'] && intval( $value ) !== 9 ) {
@matthiaspabst
matthiaspabst / 404.php
Last active April 14, 2022 12:32
Twenty Fifteen - Custom 404 page for a custom post type
<?php
/**
* The template for displaying 404 pages (not found)
*
* @package WordPress
* @subpackage Twenty_Fifteen
* @since Twenty Fifteen 1.0
*/
get_header(); ?>
@matthiaspabst
matthiaspabst / 404.php
Created February 28, 2017 09:39
Twenty Fifteen - Default 404 Page
<?php
/**
* The template for displaying 404 pages (not found)
*
* @package WordPress
* @subpackage Twenty_Fifteen
* @since Twenty Fifteen 1.0
*/
get_header(); ?>
@matthiaspabst
matthiaspabst / dl-file.php
Last active April 5, 2016 14:44
Hide media files for non-logged-in users in WordPress
<?php //Credits: http://0to5.com/protecting-wordpress-media-uploads-unless-user-is-logged-in/
require_once('wp-load.php');
If (!is_user_logged_in()){
$upload_dir = wp_upload_dir();
echo $upload_dir['baseurl'] . '/' . $_GET[ 'file' ];
wp_redirect( wp_login_url( $upload_dir['baseurl'] . '/' . $_GET[ 'file' ]));
exit();
}
list($basedir) = array_values(array_intersect_key(wp_upload_dir(), array('basedir' => 1)))+array(NULL);
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@matthiaspabst
matthiaspabst / wordpress-post-thumbnail-grid-style.css
Last active May 13, 2021 03:16
WordPress page template for a post thumbnail grid
/* Post Thumbnail Grid */
.gridcontainer h2 a{color: #333; font-size: 13px;}
.gridcontainer .griditemleft{float: left; width: 150px; margin: 0 30px 20px 0;}
.gridcontainer .griditemright{float: left; width: 150px;}
.gridcontainer .postimage{margin: 0 0 5px 0;}
.gridcontainer .postimage-title {text-align: center;}
@matthiaspabst
matthiaspabst / wordpress-404-image.php
Created February 14, 2012 17:08
404-Bild in WordPress anzeigen
<?php
if ( preg_match( '~\.(jpe?g|png|gif|svg|bmp)(\?.*)?$~i', $_SERVER['REQUEST_URI'] ) )
{
header( 'Content-Type: image/png' );
locate_template( 'images/404.png', TRUE, TRUE );
exit;
}
?>
@matthiaspabst
matthiaspabst / facebook-like-button-1.html
Created December 27, 2011 20:03
Facebook “Gefällt mir”-Button in WordPress-Theme integrieren
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink()); ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px;" allowTransparency="true"></iframe>
@matthiaspabst
matthiaspabst / teilen-links-wordpress-1.html
Created December 27, 2011 18:12
Teilen-Links für Facebook, Twitter und E-Mail ohne Plugin in WordPress integrieren
@matthiaspabst
matthiaspabst / wordpress-shortcode-zweispaltig-1.php
Created December 27, 2011 18:03
WordPress Mini-Tutorial: In Artikeln und auf Seiten zweispaltig schreiben
<?php
// Shortcodes für 2 Spalten
// Linke Spalte
function basic_leftcolumn($atts, $content = null) {
if(!empty($content)){
return do_shortcode('<div class="leftcolumn">' . $content . '</div>');}
return '<div class="leftcolumn">' . $content . '</div>';
}