Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
@cameronjonesweb
cameronjonesweb / functions.php
Created May 10, 2017 23:25
[WordPress] Set the page title for a 404 page and prevent the_title filter affecting menu items
<?php
function 404_page_title( $title, $id ) {
if( is_404() && !get_post_type( $id ) ) {
$title = 'Page not found';
}
return $title;
@cameronjonesweb
cameronjonesweb / functions.php
Last active May 11, 2017 02:22 — forked from robincornett/functions.php
optional home.php--to show the posts (blog) page's title and content
<?php
add_action( 'edit_form_after_title', 'posts_page_edit_form' );
function posts_page_edit_form( $post ) {
$posts_page = get_option( 'page_for_posts' );
if ( $posts_page === $post->ID ) {
// Running this hook seems to remove the page for posts notice, it's a good idea to keep it
@cameronjonesweb
cameronjonesweb / wc-account-login.php
Last active August 3, 2018 03:45
Update WooCommerce sites to use the account page to login rather than wp-login.php
<?php
add_filter( 'login_url', 'cameronjonesweb_use_woocommerce_login_page' );
/**
* If WooCommerce is active use the account page for logging in
* @param string $login_url The URL for login.
* @param string $redirect The URL to redirect back to upon successful login.
* @param bool $force_reauth
* @return string
@cameronjonesweb
cameronjonesweb / .htaccess
Last active May 30, 2017 02:01
Redirect all from domain
RewriteEngine On
# Replace example.com with the target domain
RewriteCond %{HTTP_HOST} !example.com$ [NC]
# Any paths you wish to exclude for some reason
RewriteCond %{REQUEST_URI} !^/training
# Preserve the path
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# All to the root
RewriteRule ^(.*)$ http://example.com/ [L,R=301]
@cameronjonesweb
cameronjonesweb / .htaccess
Created May 30, 2017 04:34
Cache and GZIP
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
@cameronjonesweb
cameronjonesweb / cameronjonesweb-button-generator.php
Last active July 12, 2017 04:11
PHP button generator for WordPress
<?php
/**
* Generates a button
* @param string $label The label of the button
* @param string $link The URL to link to
* @param array $classes Additional classes to add to the button element
* @param bool $new_window Whether to open in a new window or now
* @return string The HTML button element
*/
<!DOCTYPE html>
<head>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php var_dump( have_posts() ); ?>
<?php wp_footer(); ?>
</body>
@cameronjonesweb
cameronjonesweb / hosts
Last active September 3, 2018 00:13
Spotify ad block
# Spotify ad block
0.0.0.0 adclick.g.doublecklick.net
0.0.0.0 adeventtracker.spotify.com
0.0.0.0 ads-fa.spotify.com
0.0.0.0 analytics.spotify.com
0.0.0.0 audio2.spotify.com
0.0.0.0 b.scorecardresearch.com
0.0.0.0 bounceexchange.com
0.0.0.0 bs.serving-sys.com
0.0.0.0 content.bitsontherun.com
@cameronjonesweb
cameronjonesweb / .htaccess
Created June 26, 2017 07:13
Noindex PDF files
<FilesMatch ".pdf$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
@cameronjonesweb
cameronjonesweb / cameronjonesweb-fix-author-no-posts.php
Created July 10, 2017 05:27
Fixes an issue with WordPress where the current author is empty on author archives with no posts
<?php
add_action( 'template_redirect', 'cameronjonesweb_fix_author_no_posts' );
function cameronjonesweb_fix_author_no_posts() {
global $authordata;
if( is_author() && empty( $authordata ) ) {