Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@cameronjonesweb
cameronjonesweb / gform-field-content-filter.php
Created February 16, 2020 07:23
Render the_content in a gravity forms field
<?php
$form_id = 1;
$field_id = 1;
add_filter( "gform_field_content_{$form_id}_{$field_id}", 'gfield_render_the_content', 10, 5 );
function gfield_render_the_content( $content, $field, $value, $lead_id, $form_id ) {
$content = apply_filters( 'the_content', get_the_content() );
return $content;
}
@maheshwaghmare
maheshwaghmare / snippet.php
Created October 25, 2019 08:53
Astra Portfolio - Change the text `Portfolio` with `Retreats` from post type.
<?php
/**
* Change name `Portfolio` with `Retreats`
*
* @param array $args Post type arguments.
* @param string $post_type Post type slug.
* @return array Filtered arguments.
*/
if( ! function_exists( 'astra_portfolio_change_portfolio_arguments' ) ) :
function astra_portfolio_change_portfolio_arguments( $args = array(), $post_type = '' ) {
@cameronjonesweb
cameronjonesweb / functions.php
Last active October 7, 2020 23:41
Helper function to generate post type labels
<?php
/**
* Generates the post type labels
*
* @param string $single Singular name of the post type.
* @param string $plural Plural name of the post type.
* @param array $overrides Override any generated labels.
* @return array The post type labels
*/
function cameronjonesweb_generate_post_type_labels( $single, $plural, $overrides = [] ) {
@mennwebs
mennwebs / functions.php
Last active September 2, 2022 19:11
Use ACF image field as avatar
<?php
/**
* Use ACF image field as avatar
* @author Mike Hemberger
* @link http://thestizmedia.com/acf-pro-simple-local-avatars/
* @uses ACF Pro image field (tested return value set as Array )
*/
add_filter('get_avatar', 'acf_profile_avatar', 10, 5);
function acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
if ( is_numeric( $id_or_email ) ) {
@maheshwaghmare
maheshwaghmare / delete-options.php
Last active June 6, 2020 22:08
Astra Portfolio - Delete the options.
/**
* Delete the options
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*/
if( ! function_exists( 'prefix_astra_portfolio_delete_options' ) ) :
function prefix_astra_portfolio_delete_options() {
delete_option( 'astra-portfolio-batch-process' );
@cameronjonesweb
cameronjonesweb / taxonomy-radio-buttons.php
Created July 20, 2019 16:18
Converts the category checkboxes to radio buttons
<?php
function cameronjonesweb_radio_taxonomy_meta_box( $post, $box ) {
ob_start();
post_categories_meta_box( $post, $box );
$meta_box = ob_get_clean();
echo str_replace( 'checkbox', 'radio', $meta_box );
}
@cameronjonesweb
cameronjonesweb / functions.php
Created May 30, 2019 23:14
Preserve taxonomy heirarchy on edit post page
<?php
add_filter('wp_terms_checklist_args', function ($args){
$args['checked_ontop'] = false;
return $args;
});
@MaximeCulea
MaximeCulea / image-missing-alt-tag.php
Last active June 6, 2020 21:31
If missing or empty image alt attribute, get the current post's title to set it
/**
* If missing or empty image alt attribute, get the current post's title to set it
* In order to be unique, use the following naming convention : 'Image n : post title'
*
* @param string $content
*
* @author Maxime CULEA
*
* @return string
*/
@MaximeCulea
MaximeCulea / column-checkbox.php
Created March 12, 2019 18:46
Add custom checkbox in admin columns with according ajax event for saving postmeta.
<?php class Post_Column {
function __construct() {
add_filter( 'manage_posts_columns', [ $this, 'columns_head' ] );
add_action( 'manage_posts_custom_column', [ $this, 'columns_content' ], 10, 2 );
add_action( 'admin_footer', [ $this, 'jquery_event' ] );
add_action( 'wp_ajax_newsletter_send_save_meta', [ $this, 'process_ajax' ] );
}
/**
* Add column header
@maxyudin
maxyudin / [WordPress] Make post (page) list table custom column sortable
Created March 8, 2019 14:09
[WordPress] Make post (page) list table custom column sortable
<?php
// https://wordpress.stackexchange.com/a/293403/11761
// Make sure to change MY_POST_TYPE, MY_CUSTOM_COLUMN and MY_META_KEY to the actual values.
// Add your custom column. Unset the date and set it again to keep it in the last column. You can skip this step.
function my_manage_MY_POST_TYPE_columns( $columns )
{
// save date to the variable