S
S
Sergey2017-10-28 14:51:51
css
Sergey, 2017-10-28 14:51:51

How not to display a block from the WordPress admin panel if the "Custom field" is empty?

How not to display the "div class="color" block from the WordPress admin panel if some "Custom field" in this block is empty? I think it will be clear from the screenshots.
59f46f49d9d54259752682.jpeg59f46f7325c06843827359.jpeg

<div class="color">
  <div class="square" style="background-color: <?php echo get_post_meta($post->ID, "s_floor1_color_4", true); ?>"></div>
  <span><?php echo get_post_meta($post->ID, "s_floor1_text_4", true); ?></span>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Brad9aga, 2019-07-31
@antosha_html

1.body in the layout never use, except for some points (I'll leave it to you).
2.Use a wrapper div for this.
3. learn css
4. (margin: 0 auto;) is not a correct entry, it is enough to specify (margin: auto;).
5. your semicolons, which do not play a role, still play a role.
https://jsfiddle.net/yjb9gnu6/
ps margin:auto this trick doesn't work if the element is not block-level or has no width specified.

M
Max Medar, 2017-10-28
@fenya-fl

Check this field for any condition. For example:

if ( get_post_meta($post->ID, "s_floorl_text_4", true) ) {
  // html here
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question