Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Last active November 6, 2023 08:11
Show Gist options
  • Save humayunahmed8/f90fdca4271e92983d058f0ab27a7e88 to your computer and use it in GitHub Desktop.
Save humayunahmed8/f90fdca4271e92983d058f0ab27a7e88 to your computer and use it in GitHub Desktop.
Allowed html tags and class in codestar metabox feild
<?php
function lcorp_section_pricing_metabox( $metaboxes ) {
$section_id = 0;
if ( isset( $_REQUEST['post'] ) || isset( $_REQUEST['post_ID'] ) ) {
$section_id = empty( $_REQUEST['post_ID'] ) ? $_REQUEST['post'] : $_REQUEST['post_ID'];
}
if ( 'section' != get_post_type( $section_id ) ) {
return $metaboxes;
}
$section_meta = get_post_meta( $section_id, 'lcorp-section-type', true );
if ( ! $section_meta ) {
return $metaboxes;
} else if ( 'pricing' != $section_meta['section-type'] ) {
return $metaboxes;
}
$metaboxes[] = array(
'id' => 'lcorp-pricing-section',
'title' => __( 'Pricing Section Settings', 'lcorp' ),
'post_type' => 'section',
'context' => 'normal',
'priority' => 'default',
'sections' => array(
array(
'name' => 'lcorp-pricing',
'icon' => 'fa fa-image',
'fields' => array(
array(
'id' => 'section_heading',
'type' => 'text',
'title' => __( 'Section Heading', 'lcorp' ),
'default' => __( 'Pricing made', 'lcorp' ),
'sanitize'=> false,
),
)
)
)
);
return $metaboxes;
}
add_filter( 'cs_metabox_options', 'lcorp_section_pricing_metabox' );
<h2 class="display-3 mb-4">
<?php
if (!empty($lcorp_section_meta['section_heading'])) {
$content = $lcorp_section_meta['section_heading'];
// Use a regular expression to add the class to the span tag
$content_with_class = preg_replace('/<span([^>]*)>/', '<span$1 class="text-underline-warning">', $content);
echo $content_with_class;
}
?>
</h2>
@humayunahmed8
Copy link
Author

image

Metabox

@humayunahmed8
Copy link
Author

image

Retrieve metabox data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment