WordPress: Hide section on all pages (editor) expect one
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I am using WordPress to put together a website.

I used wp-types toolset to create a custom post type and a post relationship to pages; there is now a Post Relationships section at the bottom of every page in the admin edit screen. The problem is, I would only like this section to show up on a couple of pages.

Is there something I can add to functions.php (or another alternative) to hide (using CSS?) this section from all pages expect for those particular ones.

The section div id that I want to hide is #wpcf-post-relationship and the data post id of the pages that I would like it to be visible are 143 and 23.

Crowdsource coding tasks.

2 Solutions

Try this.



body.page-id-143 #wpcf-post-relationship, body.page-id-23 #wpcf-post-relationship{
display:block !important;

Let me know if that worked or else ping me in skype,
skype ID: bhuvan530531

Thanks for the attempt, however that solution works for the outputted pages. What I am referring to is the page edit screen in the admin area of WordPress.
John84 almost 6 years ago

Below should work,
I have tested it already.

add_action( 'admin_head', 'add_custom_css_for_hiding' );

function add_custom_css_for_hiding(){
if( is_admin() ) {
global $pagenow;
if($_GET['post_type'] == 'page' || get_post_type($_GET['post']) == 'page') {

if(($_GET['post'] == 143) || ($_GET['post'] == 23)) {
echo '#wpcf-post-relationship{display:block;';
echo '#wpcf-post-relationship{display:none;}';

View Timeline