after checked the checkbox in backend, dont show social link on frontend

Question

I want to do something like if I checked/unchecked a checkbox in admin then all social links in the page footer on fronted hide/show.

function add_custom_meta_box() 
{add_meta_box("demo-meta-box", "Add or remove social link from footer", "custom_meta_box_markup", "page", "advanced", "high", null); }
add_action("add_meta_boxes", "add_custom_meta_box");

/* Displaying Fields in a Custom Meta Box */
function custom_meta_box_markup($object)
{
wp_nonce_field(basename(__FILE__), "meta-box-nonce");

?>
    <div class="meta_chk">
        <?php
            $checkbox_value = get_post_meta($object->ID, "meta-box-checkbox", true);
            if($checkbox_value == "")
            {
                ?>
                    <input name="meta-box-checkbox" type="checkbox" value="true">
                <?php
            }
            else if($checkbox_value == "true")
            {
                ?>  
                    <input name="meta-box-checkbox" type="checkbox" value="true" checked>
                <?php
            }
        ?>
        <label for="meta-box-checkbox">Remove social link</label>
    </div>
<?php  
}
/* Storing Meta Data */

function save_custom_meta_box($post_id, $post, $update)
{
if (!isset($_POST["meta-box-nonce"]) ||     !wp_verify_nonce($_POST["meta-     box-nonce"], basename(__FILE__)))
    return $post_id;

if(!current_user_can("edit_post", $post_id))
    return $post_id;

if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
    return $post_id;

$slug = "post";
if($slug != $post->post_type)
    return $post_id;

$meta_box_checkbox_value = "";

if(isset($_POST["meta-box-checkbox"]))
{
    $meta_box_checkbox_value = $_POST["meta-box-checkbox"];
}   
update_post_meta($post_id, "meta-box-checkbox", $meta_box_checkbox_value);
}

add_action("save_post", "save_custom_meta_box", 10, 3);
0
, WP_boss 7 years 2016-07-28T01:32:33-05:00 0 Answers 61 views 0

Leave an answer

Browse
Browse