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 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
- Using a new WP_Query inside the loop
- wp_Query with mutuplea values returns all posts
- Load more posts using AJAX based on posts inside WP_Query
- echo cutom css code to WordPress page template file ? is this safe?
- in_array not working on dev server but works on localhost
- wp_query – Exclude the first thumbnail from lazy loading on archives
- meta_query search names when they have middle initials
- How to call my PHP function with AJAX ? wp_query
- WordPress sorting posts by date and title using a dropdown
- Custom search query on WordPress page not working
- WP query posts BUT show the most recent and one per author
- How to get specific multiple pages excerpts at homepage?
- Ajax filter with loadmore button
- Define global custom post
- How to select post ID for given parent name with nested prepared queries?
- posts_per_page displays only 2 posts instead of 4 posts
- Usermeta data unserialize, extract and display in table in WordPress
- Use WPQuery to match to specific repeater row in post
- Query by pagename not Working
- Query on a repeater date (acf)
- WP_QUERY post_in problem
- Display featured image of post type category
- how to get data from two different table from wordpress database
- Delete post meta by serialized meta value
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- Assign meta_query value to php variable
- get_filtered_term_product_counts – Get product terms if any products
- Trying to get pagination working on WP_Query() post grid
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Add code to the header of posts by particular author
- Search for single post by 2 tags
- Paged WP_Query is quitting on page 3
- Getting info about selected posts using one WP_Query
- Get Child of Child Pages in custom Menu
- List all ACF field values across every post on one page
- WordPress search query, how to modify the sql
- Modify post image in full size
- Wp-query output correct, but the loop shows one less item (only sometimes)
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- How to display sticky post always at the top (before regular post) in wordpress?
- WP_Query To Display Product Of Brand On Taxonomy Page
- Meta query not showing result properly
- Combine multiple queries, array_unique returns nothing
- How to display last whole post on the homepage
- Query to show average # of months all accounts with specific role have been active
- wordpress query returning unexpected results
- Woocommerce Related Product by 2 taxonomy
- Custom Post type Ajax search results
- Help on Wp_query to print an term
- Making list of posts with chosen description
- Query doesn’t display text data with apostrophes
- Ordering / grouping posts by datepicker ACF
- How to return count of items found in SQL query
- Include search tags and users in my search results system
- Display only upcoming events / Show all events when archive year is selected
- Add custom taxonomy to custom search for posts
- making a search.php query
- Escaping a Single Quote in str_replace for Nav Function
- wp_query beginner
- Querying posts from wordpress with 2 or more conditionals
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- SQL Query Search page
- Variable ++ in query loop
- Execute multiple PHP Snippets causes error?
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Count custom posts type and filter by tag
- Three different queries on same page
- How to sort custom sortable column by custom table value
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- How to sort search result by post_title, then by post_content
- How do I exclude the current post from the upcoming post query
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- wp_logout action hook is not firing
- How to show correct td of table tags in wp_query loop
- Exclude first post from wp query
- how to escape alert/window.location.replace with variable
- Show post in elementor based on views and specific category with query id feature in elementor
- Check for a value in a custom query
- How to make posts_like_dislike reference current post when iterating?
- AND and OR in my CPT search query depending on checkbox
- Add css class ID to largest and smallest number a custom field in wp_query
- 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?
- Add up all numbers from a WordPress query [closed]
- Developing a “fallback” for empty wp_query results based on post dates
- Display posts in correct month order using single date custom field
- How can I save the HTML output of a WP_Query function as a variable?
- WordPress query_posts with multiple tax_query