How to use foreach and if statement within array of arrays?

Figured it out as per this answer. You cannot put any loop or control structure if/else as array value or anywhere within array(). Example $contact_list = []; $contact_list[‘url’] = ‘Website’; foreach ( wp_get_user_contact_methods() as $value => $label ) { $contact_list[$value] = $label; } $settings_fields = array( // Parent array ‘dsbl_basics’ => array( // Child array … Read more

Looping single post in a theme

Firstly, you don’t need to check with is_single() in single.php. WordPress will automatically recognize it for single post. Secondly, breakdown your template with in parts. Such as break your main loop code in content-single.php and call it in single.php with get_template_part(‘content’, ‘single’). So you single.php template will look like below- <?php while ( have_posts() ) … Read more

How to return a blank page

To return a blank page that’s been created in a plugin like so: Example: blank-page.php <?php // Blank PHP page… Use the following function: add_filter( ‘some_tag’, ‘wpse_238008_blank_page’, 99 ); function wpse_238008_blank_page() { // Template with an empty page define( ‘PLUGIN_PATH’, plugin_dir_path( __FILE__ ) ); return PLUGIN_PATH . ‘/path/to/blank-page.php’; } Replace the following to suit your … Read more