How to append to an array and return the results in a filter?

Note this is mostly a PHP programming question about arrays and is better asked on e.g. Stack Overflow. As shown in the docs array_push() acts on the array and takes multiple parameters which get added as array values. It doesn’t add key => value pairs to associative arrays, and it doesn’t return the array itself, … Read more

List all blogs, but exclude the main site

I’ve never used it, but it looks like get_main_site_id is what you want to figure that out, so therefore your code might look like: $mainSiteId = get_main_site_id(); foreach ($user_blogs AS $user_blog) { if ($userblog->site_id != $mainSiteId) { echo ‘<li><a href=”‘.$user_blog->siteurl.'”>’.$user_blog->blogname.'</a></li>’; } }

Undefined offset: 3 in custom function

You assumed get_field would always return images, but what if there are no images to return? $images = get_field(‘fl_gallery’); $image = $images[$no]; The code never checks $images to see if it’s empty, or an error value. On top of that, what if it returned images, but it returned 3 images, and $no is 4? You … Read more

Remove extract from function

It’s very simple: Just assign the value of shortcode_atts() (which is an array) to a variable and use it to access the shortcode attributes in the same way you access the items in any other arrays: $atts = shortcode_atts( array( ‘no’ => 1, ), $atts ); // Use $atts[‘no’] to get the value of the … Read more

Override user-edit.php to design own profile page

Depending on the scope of your project, I would recommend either using ACF (Advanced Custom Fields) which will allow you to create custom fields in your user based on their level, which you can then output into your theme. The outputting part though will require some coding knowledge to do. The other option is to … Read more

Export Form Data to a CSV then send it as an attachment – contact form 7

There are a few things omitted in the above solution, like defining the most params of wp_mail. Also I didn’t want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution. Here’s my take: add_filter( ‘wpcf7_before_send_mail’, ‘add_form_as_attachment’, 10, 3 ); … Read more