Created
October 9, 2016 15:08
-
-
Save ademilter/40e6971582bb7a54c3468f684b1bc346 to your computer and use it in GitHub Desktop.
wp custom keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $sources = array(); | |
| $keys = get_post_custom_keys(); | |
| foreach ((array)$keys as $key) { | |
| $keyt = trim($key); | |
| if (is_protected_meta($keyt, 'post')) | |
| continue; | |
| $values = array_map('trim', get_post_custom_values($key)); | |
| $value = implode($values, ', '); | |
| if ($key == "img_src_lg") { | |
| $sources[1] = '<source media="(min-width: 1200px)" srcset="' . $value . '">'; | |
| } elseif ($key == "img_src_md") { | |
| $sources[2] = '<source media="(min-width: 992px)" srcset="' . $value . '">'; | |
| } elseif ($key == "img_src_sm") { | |
| $sources[3] = '<source media="(min-width: 768px)" srcset="' . $value . '">'; | |
| } elseif ($key == "img_src_xs") { | |
| $sources[4] = '<img srcset="' . $value . '" alt="">'; | |
| } | |
| } | |
| ksort($sources); | |
| foreach ($sources as $order => $src) { | |
| echo $src; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment