Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / htaccess.txt
Last active April 28, 2017 06:49
Deny access during website installation and/or provide 503 status for Google
order deny, allow
deny from all
# geef hier uw IP adres op
Allow from 95.397.xxx.xxx
# misschien heeft u nog een 2. IP adres?
#Allow from 177.165.xxx.xxx
@finalwebsites
finalwebsites / robots.txt
Created April 28, 2017 06:55
Robots.txt example for WordPress websites
User-agent: *
Disallow: *.php
Disallow: */feed/
Sitemap: http://www.uwdomeinnaam.nl/sitemap_index.xml
<?php
$cache_time = 3600*24; // 24 hours
$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));
if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.web-development-blog.com/feed/');
@finalwebsites
finalwebsites / general-functions.php
Created March 14, 2018 13:41
General functions from the Jupiter theme (snippet)
<?php
/**
* Add a widget to the dashboard.
*
* This function is hooked into the 'wp_dashboard_setup' action below.
*/
function mk_posts_like_stats_widget() {
wp_add_dashboard_widget('mk_posts_like_stats', 'Popular Post Stats', 'mk_posts_like_stats_func');
@finalwebsites
finalwebsites / force-login-before-checkout.php
Last active August 12, 2018 12:22
This snippet for WooCommerce will force your customers to login or register before they can enter the checkout page.
<?php
/*
Redirect customers from the checkout page to the my account page
Conditions: not logged in, no guest checkout and not yes received an order
The query var redirect_to_checkout, this one is used to redirect back to the checkout after login or registration
*/
function checkout_template_redirect() {
global $wp;
$guest = get_query_var( 'guest', '' );
@finalwebsites
finalwebsites / add_noindex_for_feeds.php
Created August 15, 2018 06:04
Add noindex to your WordPress website using the X-Robots-Tag header
<?php
// add this code to your theme's functions.php file
function add_noindex_for_feeds($headers) {
$req_uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
if ( '/feed/' == substr($req_uri, -6) ) {
$headers['X-Robots-Tag'] = 'noindex';
}
return $headers;
}
@finalwebsites
finalwebsites / add_thickbox_attr.php
Last active August 19, 2018 13:44
Use the jQuery thickbox plugin for your WordPress galleries (add code to your theme's function.php file)
function add_thickbox_attributes_gallery_link( $anchor_tag, $image_id ) {
$image = get_post( $image_id );
if( isset($image->post_parent)) {
$rel = '<a class="thickbox" rel="attached-to-'.intval($image->post_parent).'"';
$anchor_tag = str_replace('<a', $rel, $anchor_tag);
}
return $anchor_tag;
}
add_filter('wp_get_attachment_link', 'add_thickbox_attributes_gallery_link', 1, 2);
@finalwebsites
finalwebsites / migrate-serverpilot-apps.php
Created October 29, 2018 06:35
Migrate Serverpilot all apps from old server to a new server
<?php
// the Serverpilot wrapper, get it the class from https://github.com/daverogers/serverpilot-php
include_once 'ServerPilot.php';
$sp_id = 'SPCLIENTID';
$api_key = 'SPAPIKEY';
// you can find those id's in the URL from your Serverpilot application
$from_server = 'MIGRATEFROM';
$to_server = 'MIGRATETO';
@finalwebsites
finalwebsites / woocommerce-custom-category-name.php
Created January 22, 2019 12:14
Add parent product category names to the woocommerce_page_title() function (hook)
<?php
add_filter( 'woocommerce_page_title', 'custom_woocommerce_page_title');
function custom_woocommerce_page_title( $page_title ) {
$queried_object = get_queried_object();
if ($queried_object->taxonomy == 'product_cat') {
$tid = $queried_object->parent;
while ($tid > 0) {
if ($parent_obj = get_term($tid, 'product_cat')) {
$tid = $parent_obj->parent;
$page_title = $parent_obj->name . ' &gt; ' . $page_title;
@finalwebsites
finalwebsites / tpl-rss-feed-for-mailchimp.php
Last active January 27, 2019 14:29
Page template to create RSS campaigns with WordPress and Mailchimp
<?php
/*
Template Name: Custom RSS Feed
*/
$numposts = 5;
$numchars = 300;
$thumbformat = 'medium';
$alt_text = 'Klik hier voor de afbeelding...';