Using a function written in my functions.php file within the header.php file

As discussed in comments you actually just want the URL. Here’s your code modified to be a get_avatar_url hook instead: add_filter(‘get_avatar_url’, ‘lb_acf_profile_avatar_url’, 10, 5); function lb_acf_profile_avatar_url($url, $id_or_email, $args) { $user=””; // Get user by id or email if (is_numeric($id_or_email)) { $id = (int) $id_or_email; $user = get_user_by(‘id’, $id); } elseif (is_object($id_or_email)) { if (!empty($id_or_email->user_id)) { … Read more

Get product attribute for Simple product in WooCommerce

Building on Loic’s answer for an attribute of pa_manufacturer: if ( get_post_type( $post ) === ‘product’ && ! is_a($product, ‘WC_Product’) ) { $product = wc_get_product( get_the_id() ); // Get the WC_Product Object } $product_attributes = $product->get_attributes(); // Get the product attributes // Output $manufacturer_id = $product_attributes[‘pa_manufacturer’][‘options’][‘0’]; // returns the ID of the term $manufacturer_name = … Read more

Why WordPress uses 4 tables to manage terms

Well, it uses 3 tables. The fourth one (wp_termmeta) is just a way of allowing you to store some meta values for terms (icons, additional descriptions and so on). Citing from Codex: wp_terms – The categories for both posts and links and the tags for posts are found within the wp_terms table. wp_termmeta – Each … Read more

API JSON Data in WordPress

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to … Read more

Admin Menus – Name Menu different from first Submenu [duplicate]

The first menu item typically is the parent item and shares the name with that item, you can however manually update the entry directly in the $submenu variable, like so.. add_action( ‘admin_menu’, ‘jp_create_admin_pages’ ); function jp_create_admin_pages() { global $submenu; add_menu_page(‘Members’,’Members’,’manage_options’,’members’,’jp_handle_admin_members’); add_submenu_page(‘members’,’Membership Types’,’Membership Types’,’manage_options’,’membership_types’,’jp_handle_admin_membership_types’); $submenu[‘members’][0][0] = ‘All Members’; } That way your parent keeps the original … Read more

Theme Customizer – Dynamic CSS PHP File

@s_ha_dum is right, the ajax plugin api is the way to go. I ran into this issue myself with a dynamic js file I was generating a little while ago. Basically you would enqueue your style as follows: wp_enqueue_style( ‘dynamic-css’, admin_url(‘admin-ajax.php’).’?action=dynamic_css’, $deps, $ver, $media ); Then create a function to load your dynamic css file: … Read more

WordPress media upload “HTTP error”

I figured out how to fix my problem. In my nginx config file (/etc/nginx/nginx.conf) I added client_max_body_size 100m; at the end of the #Basic Settings in the http {} section. I hope this answer will help some of you and please tell me if there is any better solution to this problem.

Should I use wp_mail or PHP’s mail? [duplicate]

WordPress offers its own mailing system. I suggest you use that instead of PHP’s native mail. wp_mail accepts five arguments: wp_mail( $to, $subject, $message, $headers, $attachments ); So your code can be written this way: // Set the headers $headers[] = ‘From: ‘ . get_option(‘admin_email’); // Add the addresses to an array foreach($emails as $mail) … Read more

Adding Google Analytics code to the tag of specific pages

While you can add the snippet directly to header.php, a better choice is probably the wp_head action which should be triggered in any well-made, modern theme. Using this hook allows you to insert the snippet without actually modifying your theme. It might look something like this: function wpse_282929_conditionally_print_ga_snippet() { if ( ! some_conditional_tag() ) { … Read more