Skip to content

Instantly share code, notes, and snippets.

@ademilter
Created October 9, 2016 15:08
Show Gist options
  • Select an option

  • Save ademilter/40e6971582bb7a54c3468f684b1bc346 to your computer and use it in GitHub Desktop.

Select an option

Save ademilter/40e6971582bb7a54c3468f684b1bc346 to your computer and use it in GitHub Desktop.
wp custom keys
<?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