Skip to content

Instantly share code, notes, and snippets.

@paulburgess
paulburgess / get-last-fm.js
Created January 30, 2023 14:04
CF worker / last fm
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
/**
* @param event
*/
async function handleRequest(event) {
const cache = caches.default
@paulburgess
paulburgess / wp_edits.php
Last active August 25, 2017 11:31
Add own edit / dashboard link (after disabling WP bar)
<?php if ( is_user_logged_in() ) { ?>
<p style="margin:40px 0;line-height:200%"><?php edit_post_link('Edit', '', ''); ?><br />
<a href="<?php echo get_dashboard_url() ?>">Dashboard</a>
</p>
<?php } ?>
@paulburgess
paulburgess / taxomony_dropdown_in_admin.php
Created September 18, 2016 15:40
Show a Wordpress custom taxonomy as filter dropdown in admin
/**
* Display a custom taxonomy dropdown in admin
* @author Mike Hemberger
* @link http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
*/
add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
global $typenow;
$post_type = 'person'; // change to your post type
@paulburgess
paulburgess / add_text.php
Last active December 15, 2017 08:40
Change Wordpress Featured Image label
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_instruction');
function add_featured_image_instruction( $content ) {
return $content .= '<p>The Featured Image is an image that is chosen as the representative image for Posts or Pages. Click the link above to add or change the image for this post. </p>';
}
@paulburgess
paulburgess / term_loop.php
Created September 8, 2016 14:46
Loop through taxonomy terms and list posts with that term
<?php
$post_type = 'person';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( $taxonomy );
@paulburgess
paulburgess / odd-even.php
Created April 29, 2016 08:37
PHP check is number is odd/even
$number = 20;
if ($number % 2 == 0) {
print "It's even";
}
@paulburgess
paulburgess / caching_htaccess
Created December 24, 2015 10:27
enable caching in htaccess
# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP
##### EXPIRE CACHING - LEVERAGE BROWSER CACHING #####
# Enable expirations
@paulburgess
paulburgess / wp_monthly_archives.php
Created December 17, 2015 11:37
Wordpress monthly archives sidebar, grouped by month with year header
<ul class="side-archives">
<?php
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date)
FROM $wpdb->posts WHERE post_status = 'publish'
AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) :
?>
<li><h2 class="side-archives__year"><?php echo $year; ?></h2>
@paulburgess
paulburgess / search_results_title.php
Created December 16, 2015 22:25
Wordpress Search results title, shows search term and number of results
<h1>
<?php
global $wp_query;
echo $wp_query->found_posts;
echo "&nbsp;";
if($wp_query->found_posts > 1){
_e('results found for','leo');
} else {
_e('result found for','leo');
}