Skip to content

Instantly share code, notes, and snippets.

@kraftbj
kraftbj / functions.php
Created September 16, 2015 15:22
Related Posts: Only return posts in same categories
<?php // do not include this line if pasting into an existing php file
// This function will only return posts that are related AND has ALL of the same categories.
function jp_only_rp_in_same_category( $categories, $post_id ) {
$category_objects = get_the_category( $post_id );
if ( ! empty( $categories ) ) {
$categories = array_merge( 'categories', 'category_objects' );
return $categories;
}
@kraftbj
kraftbj / custom-facebook-admin-tag.php
Last active April 1, 2021 18:42
Add FB Admins meta tag
<?php
/*
* Plugin Name: Custom Facebook Admin Meta Tag
*/
function custom_facebook_admin_meta_tag() {
$userid = "123456";
$meta = '<meta property="fb:admins" content="' . esc_attr($userid) .'">';
echo $meta;
@kraftbj
kraftbj / functions.php
Created November 5, 2020 21:03
Remove cache test from AMP
<?php
add_filter( 'site_status_tests', function ( $tests ) {
unset( $tests['direct']['amp_persistent_object_cache'] );
return $tests;
}, 99 );
@kraftbj
kraftbj / functions.php
Created July 23, 2014 17:43
Jetpack Related Posts, filter by date
function jetpackme_related_posts_past_halfyear_only( $date_range ) {
$date_range = array(
'from' => strtotime( '-6 months' ),
'to' => time(),
);
return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'jetpackme_related_posts_past_halfyear_only' );
@kraftbj
kraftbj / functions.php
Last active October 7, 2019 20:11
Reset Jetpack Protect Local Trusted IP Setting
<?php
function jetpack_support_reset_protect_ip() {
delete_site_option('trusted_ip_header');
}
add_action( 'admin_head', 'jetpack_support_reset_protect_ip');
@kraftbj
kraftbj / plugin.php
Created May 22, 2014 18:42
Plugin Header
<?php
/**
* Plugin Name: Core Functionality
* Description: This contains all your site's core functionality so that it is theme independent.
* Version: 1.0
* Author: You
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
@kraftbj
kraftbj / functions.php
Created June 14, 2018 21:16
Akismet filter privact notice
add_filter( 'akismet_comment_form_privacy_notice_markup', 'bk_custom_akismet_markup' );
function bk_custom_akismet_markup( $markup ) {
$markup = '<p class="akismet_comment_form_privacy_notice">' . sprintf(
__( 'This site uses Akismet to reduce spam. <a href="%s" target="_blank" rel="nofollow">Learn how your comment data is processed</a>.', 'akismet' ),
'https://akismet.com/privacy/'
) . '</p>';
return $markup;
}
<?php
/*
Plugin Name: Jetpack - Disable Slideshow
Plugin URI: https://jetpack.com
Description: Disable Jetpack's slideshow feature
Author URI:
Version: 2017.07.24
License: GPL
*/
@kraftbj
kraftbj / functions.php
Created June 23, 2017 19:17
Publicize for Resumes
<?php // do not include in an existing file
add_action('init', 'kraft_wpjmresume_publicize');
function kraft_wpjmresume_publicize() {
add_post_type_support( 'resume', 'publicize' );
}
@kraftbj
kraftbj / jetpack-ads-posts-only.php
Last active April 11, 2017 15:17
Only display Jetpack Ads on posts
<?php // Remove this line if copy/pasting to an existing file.
/*
Plugin Name: Only Display Jetpack Ads on Posts
Plugin URI: https://kraft.blog
Description: Only output Jetpack Ads on posts and no other post type.
Author: Kraft
Author URI: https://kraft.im/
Version: 2016.06.15
License: GPL
*/