What does the author_nicename parameter do in get_author_posts_url()?

Say that get_author_posts_url(1) return the following URL https://example.com/author/admin/ Passing the $author_nicename will change this. So get_author_posts_url(1, ‘foo’) will result in https://example.com/author/foo/ You can also check this in the source code of get_author_posts_url(). So what does passing the second argument do? It changes the resulting URL. If you don’t provide further mechanisms, this will probably result … Read more

Exclude admin from WP_Query Contributors

I realize now that you’re not talking about WP_Query but WP_User_Query. Looking at the documentation for WP_User_Query it says this about the who parameter: who (string) – Which users to query. Currently only ‘authors’ is supported. Default is all users. Instead you can use the role parameter and exclude certain users by ID like so: … Read more

Slide in Panel WordPress Post

The reason why your query fails is the following. You are finishing the loop before your cd-panel with <?php endwhile; wp_reset_postdata(); ?> which is correct. However, after that you are simply using <?php the_title(); ?>, <?php the_content(); ?> which is just a single template tag, and in your case, outputs the title of the first … Read more

Have CSS Class Added with `is_page()` WP function

Bitwise operators expect conditionals on either side of them to evaluate to either TRUE or FALSE. If FALSE it checks the next conditional until it finds a TRUE or all conditionals have been checked. Also, the is_page() function doesn’t allow parameters to be passed in on a bitwise basis. So simply change your code to … Read more

How can you limit srcset on a single type of page?

Here’s an example for filtering out sizes above set limit from the srcset attribute on certain post type. This works for featured image and images added to the post content with Gutenberg. (Tested on Twenty Twenty theme). function filter_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { global $post; if ( $post && ‘post’ === $post->post_type … Read more

How to manage arrays from custom functions stored in functions.php?

A callback for an action doesn’t return anything, because that return value is never passed through by WordPress. Use a filter instead: add_filter( ‘listofnames’, ‘SomeNames’ ); function SomeNames() { $names=array( “john”,”edgar”,”miles”); return $names; } And in your template you call it like this: $names = apply_filters( ‘listofnames’, [] ); foreach ( $names a $name ) … Read more