How can I check if a post with a particular slug or title exists?

You can use get_page_by_title() or get_page_by_path(). By default, both return a page’s WP_Post object, from which you can extract data. If the page doesn’t exist, they’ll return null. You can also use them on post types other than the built-in page. // By slug. $slug = ‘sample-page’; $page_by_slug = get_page_by_path( $slug ); // By title. … Read more

wp_query – Exclude the first thumbnail from lazy loading on archives

Filters must always return a value. If you do not return a value, it’s the same as returning an empty value, null, etc. This is always the first parameter, or a modified/replacement version of it. So this: add_filter( ‘wp_get_attachment_image_attributes’, function( $attrs ) { if ( !is_single() && !is_page() && is_front_page() && is_archive() && is_search() ) … Read more

Display div if category has a specific parent

So effectively, I’m now able to set a parent category ID, and have all the products that exist in subcategories within that parent ID echo my desired content – definitely open to any suggestions or improvements here! I’m using this in a function, which is placing the ‘tt’ div on my target product pages in … Read more

Show full post instead of excerpt

You should use this (because the content saved in the post is unfiltered): echo apply_filters( ‘the_content’, $post->post_content ); However, be advised that you should not alter code of plugins or themes that are not created by you. If that plugin is updated, your altered code is probably gone. For themes, you could create a child … Read more