Author Bio After Post

global $post; $author_id = $post->post_author; // Get author’s display name and biographical info $author_name = get_the_author_meta( ‘display_name’, $author_id ); $author_bio = get_the_author_meta( ‘description’, $author_id ); // Get author’s avatar $author_avatar = get_avatar( $author_id, 96 ); // Only display if author…Continue reading

Assign User Role Conditionally in WordPress

/** * Assigns a specific WordPress user role based on the selected value in a WPForms multiple-choice field. * * @link https://wpforms.com/how-to-assign-user-roles-conditionally-in-wordpress/ * * @param array $user_data Array containing user registration data. * @param array $fields Array of form fields…Continue reading

Preload First Post Image

function preload_first_content_image() { if (is_single()) { $post = get_post(); if ($post) { // Get post content $content = $post->post_content; // Find first image in the content preg_match_all(‘//i’, $content, $matches); if (!empty($matches[1])) { $first_image = $matches[1][0]; echo ‘‘; } } }…Continue reading

WordPress Post Views Counter Function

function wpb_set_post_views($postID) { $count_key = ‘wpb_post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); }else{ $count++; update_post_meta($postID, $count_key, $count); } } //Get rid of prefetching to keep the count accurate remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10,…Continue reading

Prevent AIOSEO from changing the category to the primary one

add_action( ‘admin_enqueue_scripts’, function () { if ( ! function_exists( ‘aioseo’ ) ) { return; } // Remove the “Select Primary Category” box from the post editor. wp_dequeue_script( ‘aioseo/js/src/vue/standalone/primary-term/main.js’ ); }, 100 ); // Prevent AIOSEO from changing the category to…Continue reading

Generate and Send Invoice Number to Authorize.Net

/* * Include an invoice number into the set of Authorize.Net args. * * @link https://wpforms.com/developers/how-to-send-an-invoice-number-through-to-authorize-net-payments */ function wpf_dev_authorize_net_process_payment_single_add_invoice_to_args( $args, $process ) { // Replace 20 in $process->fields[20] to an id of your invoice field. if ( isset( $process->fields[20][ ‘value’…Continue reading