Skip to content

Instantly share code, notes, and snippets.

View someguy9's full-sized avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
<body style="margin:0;padding:0;height:100vh;width:100vw;">
<div style="display:flex;align-items:center;height:100%;width:100%;justify-content:center;background:url('{{background}}')">
<h1 style="font-size:3.2em;color:#fff;text-shadow:0 8px 8px rgba(0,0,0,0.3)">{{title}}</h1>
</div>
</body>
<?php
// Get the current post or page's slug
$slug = get_post_field( 'post_name', get_post() );
echo $slug;
// Get slug for a post or page by ID
$post_id = 1;
echo get_post_field( 'post_name', $post_id );
@someguy9
someguy9 / wordpress-post-slug.php
Created October 31, 2022 16:23
Get the current post slug in WordPress
<?php
global $post;
$slug = $post->post_name;
<?php
$meta_query_args = array(
'meta_query' => array(
array(
'key' => 'my_date_field',
'value' => array( strtotime('2022-01-01'), strtotime('2022-12-31') ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
)
@someguy9
someguy9 / wordpress-query-posts-between-dates.php
Created October 28, 2022 15:15
Using meta_query to query posts between dates in WordPress
<?php
$meta_query_args = array(
'meta_query' => array(
array(
'key' => 'my_date_field',
'value' => array( '2022-01-01', '2022-12-31' ),
'type' => 'date',
'compare' => 'BETWEEN'
)
)
@someguy9
someguy9 / increase-wordpress-auto-scaling.php
Last active October 25, 2022 15:13
Increase the image threshold for WordPress auto resize feature
<?php
// Increase the image resize threshold to 4000px on the longest edge
function smartwp_big_image_size_threshold( $threshold ) {
return 4000;
}
add_filter( 'big_image_size_threshold', 'smartwp_big_image_size_threshold', 999, 1);
@someguy9
someguy9 / disable-wordpress-auto-scaling.php
Last active October 25, 2022 14:56
Disable image scaling in WordPress (Introduced in WordPress 5.3)
<?php
// Disable WordPress' automatic image scaling feature
add_filter( 'big_image_size_threshold', '__return_false' );
@someguy9
someguy9 / rankmath-mightyshare-title.php
Last active January 21, 2023 22:41
Use RankMath title for MightyShare.io renders in WordPress https://mightyshare.io/
<?php
// If RankMath is active & a meta title is set use it with MightyShare instead of post title
function mightyshare_use_rankmath_seo_title( $template_options ) {
if ( in_array( 'seo-by-rank-math/rank-math.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
global $post;
$rankmath_title = RankMath\Post::get_meta( 'title', $post->ID );
if(!empty($rankmath_title)){
// Use RankMath title for MightyShare
$template_options['title'] = $rankmath_title;
}
@someguy9
someguy9 / display-current-post-author-avatar.php
Created August 4, 2022 14:45
Show the author avatar of the current WordPress post.
<?php
// Display current post's author avatar (includes <img> tag)
echo get_avatar( get_the_author_meta( 'ID' ), 96 );
// Display current post's author avatar URL
echo get_avatar_url( get_the_author_meta( 'ID' ), array( 'size' => 96 ) );
@someguy9
someguy9 / wordpress-get-current-user-logged-in-avatar.php
Created August 4, 2022 14:25
Get the current avatar for logged in user in WordPress
<?php
// Ensure user is logged in
if( is_user_logged_in() ) {
// Display current logged in user's avatar (includes <img> tag)
echo get_avatar( get_current_user_id(), 96 );
// Display current logged in user's avatar URL
echo get_avatar_url( get_current_user_id(), array( 'size' => 96 ) );
}