Skip to content

Instantly share code, notes, and snippets.

@sunriseweb
sunriseweb / yoast-auto-generate-meta-description.php
Last active October 28, 2019 12:01
Divi auto-generate Yoast WordPress SEO meta descriptions
<?php
/* Fixes Divi page builder problem not allowing Yoast to auto-generate meta descriptions
* Updated August 22, 2016
*/
add_filter( 'wpseo_metadesc', 'divi_auto_gen_meta_description' ); //see https://yoast.com/wordpress/plugins/seo/api/
function divi_auto_gen_meta_description($metadesc) {
if( trim($metadesc) == '' ) {
global $post;
$rendered_content = apply_filters('the_content', $post->post_content);
$newmetadesc = strip_tags( $rendered_content );
@sunriseweb
sunriseweb / customtaxorder_exclude_taxonomies.php
Last active August 30, 2015 14:00
Add filter to Custom Taxonomy Order NE plugin so that taxonomies list in customtaxorder_wp_get_object_terms_order_filter function can be modified.
<?php
/*
* customtaxorder_wp_get_object_terms_order_filter
* wp_get_object_terms is used to sort in wp_get_object_terms and wp_get_post_terms functions.
* get_terms is used in wp_list_categories and get_terms functions.
* get_the_terms is used in the the_tags function.
* tag_cloud_sort is used in the wp_tag_cloud and wp_generate_tag_cloud functions (but then the get_terms filter here does nothing).
* Default sorting is by name (according to the codex).
*
*/
@sunriseweb
sunriseweb / functions.php
Created January 23, 2015 22:22
Makes Divi Pagebuilder work with Yoast SEO
//Enable shortcodes in WordPress SEO generated Meta Description with HTML removed
add_filter( 'wpseo_metadesc', 'am_enable_shortcodes_removed_html' ); //see https://yoast.com/wordpress/plugins/seo/api/
function am_enable_shortcodes_removed_html($metadesc) {
if( strpos($metadesc, 'et_pb_section') !== FALSE ) {
global $post;
$rendered_content = apply_filters('the_content', $post->post_content);
$newmetadesc = strip_tags( $rendered_content );
return substr($newmetadesc, 0, 156);
@sunriseweb
sunriseweb / display-rss-feed.php
Created September 18, 2014 19:04
Display RSS Feed in WordPress
/**
* Display RSS feed
* - can be called via shortcode
*/
function display_rss_feed($args) {
extract(shortcode_atts(array(
"rssurl" => 'http://incontactunitedchurch.blogspot.com/feeds/posts/default?alt=rss'
), $atts));
// Get a SimplePie feed object from the specified feed source.
@sunriseweb
sunriseweb / show_genesis_archive_title.php
Last active August 29, 2015 14:03
Show Titles on Archive pages and Blog page
<?php
//* Show titles on genesis archive pages - including blog page - is_home()
add_action ( 'genesis_before_loop', 'twpg_show_archive_title' );
function twpg_show_archive_title() {
if (is_category()) {
echo '<h1 class="entry-title">' . single_term_title('Articles in category: <span>', false) . '</span></h1>'; //Display Category or Tag title
@sunriseweb
sunriseweb / et_postinfo_meta.php
Created April 30, 2014 12:06
Remove trailing pipe from single post meta in Divi child theme by modifing et_postinfo_meta in functions.php
<?php
//* Modify post meta to get rid of trailing pipe
function et_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more ){
global $themename;
$postinfo_meta = '';
if ( in_array( 'author', $postinfo ) )
$postinfo_meta .= ' ' . esc_html__('by',$themename) . ' ' . et_get_the_author_posts_link() . ' | ';
@sunriseweb
sunriseweb / customize_genesis_search_query.php
Last active January 3, 2016 03:28
Modify search query using pre_get_posts in genesis theme.
<?php
/**
* Customize Search Query
*
* @author Brad Trivers
* @link http://sunriseweb.ca
* @param object $query data
*
*/
add_action( 'pre_get_posts', 'hotbuys_search_query' );
@sunriseweb
sunriseweb / acf5_get_acf_field_groups_by_cpt.php
Last active May 18, 2021 08:11
Get ACF (Advanced Custom Field) field groups with their fields for a given custom post type. i.e. where the ACF location rule is "post_type == cpt".
/**
* Returns an array of field groups with fields for the passed CPT, where field group ACF location rule of "post_type == CPT" exists.
* - each field group points at an array of its fields, in turn pointed at an array of that field's detailed information:
* - array of info for each field [ ID, key, label, name, type, menu_order, instructions, required, id, class, conditional_logic[array()], etc. ]
*
* @since 1.0.0
*/
function get_acf_field_groups_by_cpt($cpt) {
// need to create cache or transient for this data?
@sunriseweb
sunriseweb / wppb.edit.profile.php
Created October 8, 2013 14:47
Profile Builder Pro changes to /wp-content/plugins/profile-builder-pro/front-end/wppb.edit.profile.php changes to support AutoChimp integration.
<?php
/*
wp_update_user only attempts to clear and reset cookies if it's updating the password.
The php function setcookie(), used in both the cookie-clearing and cookie-resetting functions,
adds to the page headers and therefore must be called within the first php tag on the page, and
before the WordPress get_header() function. Since wp_update_user needs this, it must be at the
beginning of the page as well.
*/
$changesSaved = 'no';
$changesSavedNoMatchingPass = 'no';
@sunriseweb
sunriseweb / wppb.register.php
Last active December 25, 2015 00:09
Profile Builder Pro changes to /wp-content/plugins/profile-builder-pro/front-end/wppb.register.php changes to support AutoChimp integration.
<?php
/* Hook to change auto generated password */
add_filter('random_password', 'signup_password_random_password_filter');
/**
* Function that changes the auto generated password with the one selected by the user.
*/
function signup_password_random_password_filter($password) {
global $wpdb;
if ( ! empty($_GET['key']) ) {