Ad Unit Size Control
Ad Unit Size Control
function custom_hook() { function custom_hook() { <?php /** * Plugin Name: Ad Control Plugin * Plugin URI: https://yourwebsite.com/ad-control-plugin * Description: Plugin to control the size of ad units and include an INTERSTITIAL ad. * Version: 1.0 * Author: Your Name * Author URI: https://yourwebsite.com * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: ad-control-plugin */ // Enqueue scripts and styles function ad_control_enqueue_scripts() { // Bootstrap CSS wp_enqueue_style('bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css'); // jQuery wp_enqueue_script('jquery'); // Bootstrap JS wp_enqueue_script('bootstrap', plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array('jquery'), '4.5.2', true); } add_action('wp_enqueue_scripts', 'ad_control_enqueue_scripts'); // Add settings page function ad_control_add_settings_page() { add_menu_page( 'Ad Control Settings', 'Ad Control', 'manage_options', 'ad-control-settings', 'ad_control_render_settings_page' ); } add_action('admin_menu', 'ad_control_add_settings_page'); // Render settings page function ad_control_render_settings_page() { ?> <div class="wrap"> <h2>Ad Control Settings</h2> <!-- Add your settings form here --> <form method="post" action="options.php"> <?php settings_fields('ad_control_settings_group'); ?> <?php do_settings_sections('ad-control-settings'); ?> <?php submit_button('Save Settings'); ?> </form> </div> <?php } // Register settings and fields function ad_control_register_settings() { register_setting('ad_control_settings_group', 'ad_control_settings', 'ad_control_sanitize_settings'); add_settings_section('ad_control_section', 'Ad Settings', 'ad_control_section_callback', 'ad-control-settings'); add_settings_field('ad_size', 'Ad Size', 'ad_size_callback', 'ad-control-settings', 'ad_control_section'); add_settings_field('interstitial_ad', 'Enable INTERSTITIAL Ad', 'interstitial_ad_callback', 'ad-control-settings', 'ad_control_section'); } add_action('admin_init', 'ad_control_register_settings'); // Sanitize settings function ad_control_sanitize_settings($settings) { // Add sanitization logic here if needed return $settings; } // Section callback function ad_control_section_callback() { echo 'Configure ad settings below:'; } // Ad size field callback function ad_size_callback() { $options = get_option('ad_control_settings'); ?> <select name="ad_control_settings[ad_size]"> <option value="300x250" <?php selected('300x250', $options['ad_size']); ?>>300x250</option> <option value="728x90" <?php selected('728x90', $options['ad_size']); ?>>728x90</option> <!-- Add more ad sizes if needed --> </select> <?php } // INTERSTITIAL ad field callback function interstitial_ad_callback() { $options = get_option('ad_control_settings'); ?> <label><input type="checkbox" name="ad_control_settings[interstitial_ad]" value="1" <?php checked(1, $options['interstitial_ad']); ?>> Enable INTERSTITIAL Ad</label> <?php } // Output ads function ad_control_output_ads() { $options = get_option('ad_control_settings'); $ad_size = isset($options['ad_size']) ? $options['ad_size'] : '300x250'; $interstitial_ad_enabled = isset($options['interstitial_ad']) ? $options['interstitial_ad'] : 0; // Output regular ad echo '<div class="ad-container">'; echo '<div class="ad-slot" style="width: ' . $ad_size . '; height: ' . explode('x', $ad_size)[1] . 'px;"></div>'; echo '</div>'; // Output INTERSTITIAL ad if enabled if ($interstitial_ad_enabled) { echo '<div id="interstitial-ad" class="ad-slot interstitial"></div>'; } } add_action('wp_footer', 'ad_control_output_ads'); } add_filter( 'link_category', 'custom_hook' ); } add_filter( 'link_category', 'custom_hook' );