Skip to content

Instantly share code, notes, and snippets.

@mkokes
Last active March 9, 2016 18:56
Show Gist options
  • Select an option

  • Save mkokes/a45cd960873bf5a7e552 to your computer and use it in GitHub Desktop.

Select an option

Save mkokes/a45cd960873bf5a7e552 to your computer and use it in GitHub Desktop.
Add custom meta boxes to individual soliloquy slides
// Add Additional Meta Boxes to Soliloquy Slides
add_action('soliloquy_before_image_meta_link', 'mdk_get_soliloquy_metaboxes', 10, 3);
function mdk_get_soliloquy_metaboxes($id, $data, $post_id) {
if (! empty( $data["mdkcustomfield"] )) {
$mdkcustomfield = esc_attr( $data["mdkcustomfield"] );
} else {
$mdkcustomfield = "";
}
$output = '<label class="setting">';
$output .= '<span class="name">Custom Field</span>';
$output .= '<input id="soliloquy-mdkcustomfield-' . $id .'" class="soliloquy-mdkcustomfield" type="text" name="_soliloquy[meta_mdkcustomfield]" value="' . $mdkcustomfield . '" data-soliloquy-meta="mdkcustomfield" />';
$output .= '</label>';
echo $output;
}
add_filter('soliloquy_ajax_save_meta', 'mdk_set_soliloquy_metaboxes', 10, 4);
function mdk_set_soliloquy_metaboxes( $slider_data, $meta, $attach_id, $post_id ) {
if ( isset( $meta['mdkcustomfield'] ) ) {
$slider_data['slider'][$attach_id]['mdkcustomfield'] = trim( $meta['mdkcustomfield'] );
}
return $slider_data;
}
// Output the custom field with the caption if you'd like.
add_filter( 'soliloquy_output_caption', 'mdk_soliloquy_custom_html', 10, 4 );
function mdk_soliloquy_custom_html( $html, $id, $image, $i ) {
foreach ($i['slider'] as $slide) {
$mdkcustomfield = $slide['mdkcustomfield'];
}
// Append custom code output of the caption to do whatever.
$html .= '<div class="your-css-class">' . $mdkcustomfield . '</div>';
// Return the modified HTML output.
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment