Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Display Custom Field LAbel only if not empty

Posted on 2012-04-07
Medium Priority
Last Modified: 2012-04-11
I am using the Custom Content Manager plugin with wordpress,  and have difiend my custom fields.

One of my custom fields, I want to display a <h3> title </h3  along with a link which is inserted in the custom field.

<h3>Some Title</h3>
<?php print_custom_field('audio:to_link', 'Check out my soundcloud page'); ?>

How can i modifiy this so that if their is no entry in the custom field,  the title does not appear on my page,  I only want to display the <h3> Title  if the custom field is used.
Question by:Jon Imms
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 37819145
There may be a better WP-specific answer, but this strategy will probably work.  Determine what WP produces when you call the php print_custom_field() function with no entry in the custom field.  You can use view source to make this determination.  It might produce an empty string or an empty link tag or something like that.  Once you know that, assign it to a variable so you can test it.  Then you can do something like this (assuming that the function produces a NULL string).
$p_c_empty = NULL;
print_custom_field('audio:to_link', 'Check out my soundcloud page');
$p_c_field = ob_get_clean();
if ($p_c_field != $p_c_empty)
    echo "<h3>Some Title</h3>" . PHP_EOL;
    echo $p_c_field;

Open in new window

HTH, ~Ray

Author Comment

by:Jon Imms
ID: 37820462
That did not work sorry.  It is displaying <h3>Some Title</h3> on pages where their ie no link in the custom field.
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 37821196
Please re-read the response.  I do not have your web site available to me, so you must do a little bit of your own research.  Specifically, you will need to find out what a variable contains:
It might produce an empty string or an empty link tag or something like that.  Once you know that, assign it to a variable so you can test it.
You will need to use var_dump($p_c_field) to determine what you should assign to the variable named $p_c_empty.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question