That’s question is only relevant, because WordPress use a mix from a coding language and layout language. If you would use a template language, syntax, than is this topic not relevant.
But to your question. If you use your example source for a Theme, much more layout language like html, then I prefer the first one – it is much more readable for designer and users, there must read the markup. It is easier to create an overview about the markup, have you the open and closing tags etc.
For the include in plugins, code with more logic and flow is the second example easier to implement. The main topic is php, not markup and this should it visible in the source. That’s also a point to think about to exclude this markup in template files and separate the markup from the logic.
Related Posts:
- is_page() not working from within a plugin
- Build a content and excerpt grid loop with paging and options for # of posts
- Using Cookie Data For WP_Query Loop
- wp_delete_post deletes all posts instead of just expired ones
- Alter secondary loop to exclude posts from current page category
- Trim first 2 words of the exceprt
- Display Post co-authored in Author Page
- Can an array be used as a meta_query value?
- Sorting Posts | Alphabetical Order
- Looking for most performant way to execute several similar WP queries within shortcodes
- Get the last month with posts using a recursive function…
- How to query for pages/post depending on slug?
- WordPress custom slug (endpoint) and compare all links
- wp_query with cat not working
- How to use an associative array in post__in with WP_Query?
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Display a specific category of products in shop page and disable code for specific actions
- WordPress, AJAX and pre_get_posts using conditional tags
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- How to escape attachment image caption text?
- Custom query, checking values of multiple meta keys
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WordPress theme options error
- Get posts from multiple post type
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to add div blocks after certain set of post
- the_posts_pagination() not working in wpquery
- WP_Query: getting posts where custom field exists
- Convert a string into a decimal number for use in query
- Increment paged on WP_Query
- Hide posts if user is added to it WP_query
- Custom route and query
- Getting posts to exclude from array
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Custom post type permalinks do not appear using the link functions
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Modify main query before it run without pre_get_post
- WordPress WP_Query without query GET parameters
- Sort posts in a specific way
- array_rand not working correctly?
- WP_Query() load selected post
- How to extract information from a wp_query result?
- posts_nav_link pulling in multiple post types
- Modifying WP URL handing code?
- orderby meta_value_num is not working, giving default order
- How can I modify this code to make the search box include tags and meta
- Free search and custom taxonomy query not providing the same result
- How do I reset $wp_query in a function?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- WP_Query for woocommerce products with a pattern as a post_title
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Replace a single variable with add_filter
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- echo cutom css code to WordPress page template file ? is this safe?
- meta_query search names when they have middle initials
- Ajax filter with loadmore button
- Query by pagename not Working
- Display featured image of post type category
- Delete post meta by serialized meta value
- get_filtered_term_product_counts – Get product terms if any products
- Getting info about selected posts using one WP_Query
- List all ACF field values across every post on one page
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Query to show average # of months all accounts with specific role have been active
- Query doesn’t display text data with apostrophes
- How to return count of items found in SQL query
- Escaping a Single Quote in str_replace for Nav Function
- Querying posts from wordpress with 2 or more conditionals
- SQL Query Search page
- For each 3 posts, show a different post type
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- Masonry layout within the loop
- Escape html structure in php
- Weird Behaviour: Not all WordPress Posts appearing
- Query category-specific, paginated posts and allow viewer to change sort order
- wordpress is_main_query() breaks
- allow previews outside wordpress folder (Outsourcing WP previews)
- Advanced Taxonomy query, with 3 post types
- Why does a meta_query break this WP_Query?
- How do I run the following script from my articles page?
- Execute multiple PHP Snippets causes error?
- Three different queries on same page
- How to sort custom sortable column by custom table value
- /page/2/ redirect to 404
- How to show correct td of table tags in wp_query loop
- how to escape alert/window.location.replace with variable
- External WP_Query call from PHP crashed after version update
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- WordPress query_posts with multiple tax_query
- Filtering with Attributes – how to display all non-queried products below query
- WordPress Query with meta_key and order by another meta_key