Using WordPress ‘add_link_category_form_pre’ PHP action

The add_link_category_form_pre WordPress PHP action fires before the link category form is displayed.

Usage

add_action('add_link_category_form_pre', 'your_custom_function');
function your_custom_function($arg) {
    // your custom code here
}

Parameters

  • $arg (object) – Arguments cast to an object.

More information

See WordPress Developer Resources: add_link_category_form_pre

Examples

Add a message to inform users about guidelines for creating link categories.

add_action('add_link_category_form_pre', 'custom_message_before_form');
function custom_message_before_form($arg) {
    echo '<p><strong>Note:</strong> Please follow our guidelines while creating link categories.</p>';
}

Show the total number of existing link categories before the form.

add_action('add_link_category_form_pre', 'display_existing_link_categories_count');
function display_existing_link_categories_count($arg) {
    $categories_count = wp_count_terms('link_category');
    echo '<p>Current number of link categories: ' . $categories_count . '</p>';
}

Inject custom CSS styles for the link category form.

add_action('add_link_category_form_pre', 'add_custom_css_styles');
function add_custom_css_styles($arg) {
    echo '<style>
        .form-wrap { background-color: lightblue; }
        .form-wrap input { border-color: darkblue; }
    </style>';
}

Show a warning message if the user has reached the maximum allowed number of link categories.

add_action('add_link_category_form_pre', 'max_link_categories_warning');
function max_link_categories_warning($arg) {
    $max_categories = 50;
    $categories_count = wp_count_terms('link_category');

    if ($categories_count >= $max_categories) {
        echo '<p><strong>Warning:</strong> You have reached the maximum limit of ' . $max_categories . ' link categories.</p>';
    }
}

Add an extra input field to the link category form for storing additional information.

add_action('add_link_category_form_pre', 'add_custom_input_field');
function add_custom_input_field($arg) {
    echo '<div class="form-field">
        <label for="custom_field">Custom Field:</label>
        <input name="custom_field" type="text" id="custom_field" value="">
        <p class="description">Enter custom information related to this link category.</p>
    </div>';
}