Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have built a custom options panel which allows site owners to enter their social profiles. I then use the second code to make the links appear in the theme.

When no link is entered in the options panel, I would like there to be no link called on the page where the code is being called. Currently, it provides me with a link to the homepage of my site.

Take a look: http://themeforward.com/demo2/ - the green box is the facebook link, the purple is the google link

I know what you're thinking - why not just leave it the way it is? Because, I'm styling each link with a background image rather than using normal text links... so if I just leave it this way we will still have an image showing up advertising a social site presence, but it won't be linked. The styling can be found here: http://pastebin.com/m3PrBDae I think that may be affecting this.

In my functions

array( "name" => "Facebook Page",
    "desc" => "Enter your Facebook address. (Must include http://)",
    "id" => $shortname."_facebook",
    "type" => "text",
    "std" => ""),

array( "name" => "Google Plus",
    "desc" => "Enter your Google Plus address. (Must include http://)",
    "id" => $shortname."_google_plus",
    "type" => "text",
    "std" => ""),

How I call them

<a href="<?php echo get_option('to_facebook'); ?>"></a>
<a href="<?php echo get_option('to_google_plus'); ?>"></a>
share|improve this question
    
What does get_option('to_facebook') return? –  Chip Bennett Nov 28 '11 at 20:38
    
It returns a link that users must input in a text box in the options panel. –  AndrettiMilas Nov 29 '11 at 15:42
    
No, that's what your markup outputs. I'm asking what specifically does get_option( 'to_facebook' ) return, right now, when you output it? Does it return null, false, blank, a string, etc.? –  Chip Bennett Nov 29 '11 at 17:59
    
themeforward.com/demo2 - the green box is the facebook code, the purple is the google... it returns a link to the homepage of my site –  AndrettiMilas Nov 29 '11 at 18:28
1  
I apologize if I not asking my question clearly. I don't want to know what gets rendered, I want to know what WordPress is returning when you call get_option(). How about this: what do you get with var_dump( get_option( 'to_facebook' ) )? –  Chip Bennett Nov 29 '11 at 19:41
show 2 more comments

2 Answers

up vote 5 down vote accepted

Check if get_option returns a value and if it is not blank, then output the links. This should work for you:

<?php
if(get_option('to_facebook') && get_option('to_facebook') != '') {
     ?>
     <a href="<?php echo get_option('to_facebook'); ?>"></a>
    <?php     
}   
if(get_option('to_google_plus') && get_option('to_google_plus') != '') {
    ?>
    <a href="<?php echo get_option('to_google_plus'); ?>"></a>
    <?php
}
?>
share|improve this answer
    
This is still outputting the links when it is blank. –  AndrettiMilas Nov 28 '11 at 17:08
    
Can you please show us how you implemented the solution? –  Rutwick Gangurde Nov 28 '11 at 18:23
    
pastebin.com/y1mA2q1q - at the top of my sidebar my site - themeforward.com/demo2 –  AndrettiMilas Nov 28 '11 at 19:25
    
I should add there is styling being added to these links, and that may be creating the problem... but the styling is necessary pastebin.com/m3PrBDae –  AndrettiMilas Nov 28 '11 at 19:54
    
I modified the if statement, to include braces. It shouldn't make a difference here, but doesn't hurt to try. Otherwise, I can see nothing wrong with the code. –  Chip Bennett Nov 29 '11 at 21:55
show 2 more comments

You could try something like:

if( get_option('to_facebook') ) { 
?>
    <a href="<?php echo get_option('to_facebook'); ?>"></a>
<?php
}
share|improve this answer
    
I'm getting syntax error, unexpected '<' –  AndrettiMilas Nov 28 '11 at 17:32
    
yes sorry, i was a bit quick - you need to add <?php and ?> on first and third line. but - if @rutwicks code didn't work, I don't think my code would work either... –  ptriek Nov 28 '11 at 18:14
    
@ptriek Yes Exactly. There must be something else. –  Rutwick Gangurde Nov 28 '11 at 18:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.