According to the wordpress handbook on php coding standards, braces should be used for all blocks in the style shown below:
if ( condition ) {
action1();
action2();
} elseif ( condition2 && condition3 ) {
action3();
action4();
} else {
defaultaction();
}
The use of braces means single-statement inline control structures
are prohibited so it’s better to use the alternative syntax for
control structures (e.g.if
/endif
,while
/endwhile
) in this scenario,
especially in template files where PHP code is embedded within HTML:
<?php if ( have_posts() ) : ?>
<div class="hfeed">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID() ?>" class="<?php post_class() ?>">
<!-- ... -->
</article>
<?php endwhile; ?>
</div>
<?php endif; ?>
Related Posts:
- How does printf( __( ) ); work?
- Return HTML Template Page with PHP Function
- Displaying Logged-In User Name in WordPress Menu
- Change the filename format of saved featured images
- How to use wp_insert_user on WordPress Multisite?
- Getting the comment number relative to all the post’s comments
- How do I add a php statement to a jQuery string
- Upload images and attachments from frontend form
- Config apple-app-site-association file with wordpress
- How to use the php if statement [closed]
- lazy load comments wordpress on click
- Should I use wp_mail or PHP’s mail? [duplicate]
- Trying to use Ternary operators with WP Conditionals
- Successful or Error Message after running mysql code in functions.php
- How can one utilize a variable as a callback function name for add_settings_field
- Header has extra HTML block at top before my code
- Validate Uploaded Image using WordPress’ Built-in Functions?
- Strange wordpress slowness
- $wpdb->flush(); breaks the loop
- Global variable $post returning incorrect object
- how to make separate field in wordpress user_data_
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- Proper syntax or method for keeping url in modified isotope / category links
- Custom search results page not working with empty search
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- Which hook/action will help me solve my problem?
- Tax query in pre_get_posts not working
- how to fix error “called incorrectly, should not be accessed directly”?
- Programmatically inserting post through URL – when including wp-load.php, it’s redirecting to wp-admin/install.php
- Validation algorithm in checkout field
- curl_exec causes timeout on mod_fcgid
- Accessing WPDB Multidimensional JSON Array w/ Javascript
- If has $title in widgets
- How to replace file_get_contents() with a WordPress Filesystem call
- get href content [closed]
- Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162 [closed]
- Remove dash from blog title wordpress
- Problem with AJAX in wordpress plugin
- Include text in echoed hyperlink
- set post limit at load more ajax wordpress
- Trouble inputting variable into WP query
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- How to use AJAX to call php page with parameter
- My website is not showing Footer section
- Change header on pages displaying taxonomy items
- Listing titles and custom fields of entries within subcategories
- WordPress site with embedded menu – gives You don’t have permission to access /wp-content/themes/xxx/taxonomy-redirect.php on this server
- Show get_sub_field value if it exists [closed]
- Must filter functions receive all arguments passed to them?
- How to Display a List of Child Pages For a Parent Page in WordPress
- Prevent Company Name From Translating
- Displaying Slider in Front Page (home) using Customizr Theme
- Usage of var keyword in the core
- How to add PHP pagination to wordpress
- Slow site initial load time
- MySQL Query Returns Array () In Shortcode
- array wordpress when get is null
- Custom search query on WordPress page not working
- User meta needed in query is serialized – how to unserialize safely?
- PHP calling AJAX function that relies on passed PHP function values not working
- Order by title Child Pages displayed in a Parent Page
- PHP session not staying alive. headers already sent
- how can I call a function when time expire
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- Can an AJAX callback function access a PHP variable which was defined during initial page load?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Intermittent problem can the debug log give any clues?
- Filter by Post Type
- Move Jquery.js to Footer
- Updating the database after parsing CSV document
- Need help to create WordPress page that decodes a text file and publishes it in JSON format
- My blog posts section seems to be rendering the other blog posts inside the first? :/
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Attaching an upload to a user
- Change home_url in searchform.php to go to HTTPS instead of HTTP
- can’t grab PHP $_POST variable
- PHP is_embed error showing up
- How fix error in the WordPress loop?
- Loop 1 user randomly
- Wp_mail doesnt work
- Use WP_Query Data In Cookie
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- Is custom behaviour possible when asynchronously uploading?
- How can I show only if custom field has content [closed]
- Top menu disapears in Category Pages when filtering using ACF
- need help to arabic text in wordpress
- Sorting Meta Fields?
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- Keeping the previous get value and add another value when submitted
- Pagination not displaying
- upload images on front by user using form
- Setting WooCommerce currency programmatically
- Masking external links with internal link for member-only
- Submit cf7 form to cfdb as pdf/BLOB [closed]
- How to limit the number of posts in the wordpress loop in conjunction with the “download more” button?
- seo meta description issue in google search
- Redirect loop upon installation of my plugin
- WordPress Query – Blog Cards Duplicate issue
- PHP Works only for logged in users: [closed]