Skip to content

Instantly share code, notes, and snippets.

@amboutwe
amboutwe / yoast_seo_title_add_separators.php
Last active September 24, 2022 08:40
Add custom separators to the Yoast SEO options
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Add custom separators to the Yoast SEO options
* Credit: Yoast team
* Last Tested: September 2, 2021 using Yoast SEO 17.0 on WordPress 5.8
*/
add_filter( 'wpseo_separator_options', 'yoast_seo_title_add_separators', 10 , 1 );
@moxdev
moxdev / wp-custom-srcset.php
Created March 6, 2019 15:24
Srcset Custom Wordpress #wp
<img src="<?php echo esc_url( $sm_img ); ?>" alt="<?php echo esc_attr( $alt ); ?>"
srcset="
<?php echo esc_url( get_the_post_thumbnail_url( get_the_ID(), 'listing-thumb-sm' ) ); ?> 250w,
<?php echo esc_url( get_the_post_thumbnail_url( get_the_ID(), 'listing-thumb-md' ) ); ?> 550w,
<?php echo esc_url( get_the_post_thumbnail_url( get_the_ID(), 'listing-thumb-lg' ) ); ?> 850w,
<?php echo esc_url( get_the_post_thumbnail_url( get_the_ID(), 'listing-thumb-xlg' ) ); ?> 1150w">
@morgyface
morgyface / social.php
Last active April 11, 2024 22:37
WordPress | ACF | Social Media Links using Advanced Custom Fields and FontAwesome
<?php
if( have_rows('social_media', 'option') ):
echo '<div class="container social my-4">';
echo '<p class="follow mb-0 align-middle">Follow us</p>';
echo '<ul class="nav align-middle">';
while ( have_rows('social_media', 'option') ) : the_row();
$socialchannel = get_sub_field('social_channel', 'option');
$socialurl = get_sub_field('social_url', 'option');
echo '<li class="nav-item">';
echo '<a class="nav-link" rel="nofollow noopener noreferrer" href="' . $socialurl . '" target="_blank">';
@aibrean
aibrean / image-array.php
Last active March 25, 2024 07:25
Demystifying the ACF image field. ACF (Advanced Custom Fields) allows users to use an ID, array, or URL for images. Once the field is set up in ACF, it’s up to you to get it to work correctly in your template/theme. This is known as the “return value” in ACF.
<?php
$image = get_field('image'); // assigns the image field to the variable of $image
if( !empty($image) ){ ?> <!-- if the $image variable isn't empty, display the following: -->
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <!--displays the URL for the image variable and also the alt tag which is entered in the WordPress media library-->
<?php }; ?> <!--ends the if statement -->
@galengidman
galengidman / index.php
Created March 28, 2014 19:10
get ACF image size URL by image object
<?php
// first, get the image object returned by ACF
$image_object = get_field('my_image_field');
// and the image size you want to return
$image_size = 'thumbnail';
// now, we'll exctract the image URL from $image_object
$image_url = $image_object['sizes'][$image_size];
@Strap1
Strap1 / Convert Custom Taxonomy to Custom Post Type
Last active July 24, 2024 20:27
A very hacky and quick way to transfer a Custom Taxonomy to Custom Post Type and transfer associated metadata to Custom Meta Fields. Note: You can use this if it fits your needs, but it is custom to my set up. Use in a testing environment. It's a plugin with no interface, runs on activation and depending on the amount of data, may hit PHP timeou…
<?php
/*
Plugin Name: Convert Custom Taxonomy to Custom Post Type
Plugin URI: N/A
Description: A plugin to convert a Custom Taxonomy to a Custom Post Type and transfer associated metadata.
Version: 0.1
Author: Strap1
Author URI: http:/www.hiphopinenglish.com
/** Convert Taxonomy '%name%' to CPT '%name%' **/