Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable page's title in wp-admin from being edited?

I have a wp-network installed with users that can create pages in each site.

Each of those pages get a place in the primary menu, and only one user have permission to create all this menu.

I want to create a user only to be able to edit the content of the pages, but not the title.

How can I disable the title of the page to be edited from the admin menu for a specific user, or (far better) for a capability?

I thought only a possibility, that's editing admin css to hide the title textbox, but I have two problems:

  1. I don't like to css-hide things.
    1. I don't know where is the admin css.
    2. I know php, but don't know how to add a css hide to an element for a capability.

How do I want it to be

like image 904
jperelli Avatar asked Apr 04 '12 16:04

jperelli


People also ask

How do I turn off page titles in WordPress?

Go to any page in the backend, click Edit with Elementor, and then click the Settings gear in the bottom left corner. Now switch on Hide Title and your page title will be gone.

How do I hide page titles in WordPress CSS?

Click on the little 'settings' icon located at the bottom left corner of the page. Then toggle the hide title box to remove the title from the post or page. This same approach can be used to hide post or page title on your WordPress site.


1 Answers

You should definitely use CSS to hide the div#titlediv. You'll want the title to show in the markup so the form submission, validation, etc continues to operate smoothly.

Some elements you'll need to know to implement this solution:

  1. current_user_can() is a boolean function that tests if the current logged in user has a capability or role.
  2. You can add style in line via the admin_head action, or using wp_enqueue_style if you'd like to store it in a separate CSS file.

Here is a code snippet that will do the job, place it where you find fit, functions.php in your theme works. I'd put it inside a network activated plugin if you're using different themes in your network:

<?php

add_action('admin_head', 'maybe_modify_admin_css');

function maybe_modify_admin_css() {

    if (current_user_can('specific_capability')) {
        ?>
        <style>
            div#titlediv {
                display: none;
            }
        </style>
        <?php
    }
}
?>
like image 198
Eric Andrew Lewis Avatar answered Sep 29 '22 16:09

Eric Andrew Lewis