Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍👦
My son is my everything

Cameron Jones cameronjonesweb

👨‍👦
My son is my everything
View GitHub Profile
@cameronjonesweb
cameronjonesweb / functions.php
Created May 10, 2017
[WordPress] Set the page title for a 404 page and prevent the_title filter affecting menu items
View functions.php
<?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 — forked from robincornett/functions.php
optional home.php--to show the posts (blog) page's title and content
View functions.php
<?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 Aug 3, 2018
Update WooCommerce sites to use the account page to login rather than wp-login.php
View wc-account-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
Redirect all from domain
View .htaccess
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]
View .htaccess
<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 Jul 12, 2017
PHP button generator for WordPress
View cameronjonesweb-button-generator.php
<?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
*/
View index.php
<!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 Sep 3, 2018
Spotify ad block
View hosts
# 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
View .htaccess
<FilesMatch ".pdf$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
@cameronjonesweb
cameronjonesweb / cameronjonesweb-fix-author-no-posts.php
Created Jul 10, 2017
Fixes an issue with WordPress where the current author is empty on author archives with no posts
View cameronjonesweb-fix-author-no-posts.php
<?php
add_action( 'template_redirect', 'cameronjonesweb_fix_author_no_posts' );
function cameronjonesweb_fix_author_no_posts() {
global $authordata;
if( is_author() && empty( $authordata ) ) {
You can’t perform that action at this time.