4

I am trying to add my this code into head using wp_head action,

But I am getting this error Fatal error: Can't use function return value in write context on line 130 line number 130 is on if ( !empty ( display_header_text() ) ) : ?>

Here is my code

<?php
129:function _display_header_text() {
130:if ( !empty ( display_header_text() ) ) : ?>
131:<style type="text/css" id="_display_header_text">
132:    .mainHeader a img {
133:        display:none;
134:    }
135:</style>
136:<?php endif; }
137:add_action('wp_head','_display_header_text');
138:?>
139:
140:<?php
141:function _is_admin_bar_showing() {
142: if( is_admin_bar_showing() ):?>
143:<style type="text/css" id="_is_admin_bar_showing">
144:    .fixedHeader {
145:        top:32px;
146:    }
147:</style>
148:<?php endif; }
149:add_action('wp_head','_is_admin_bar_showing');
150:?>

my this code is working fine in localhost without any error, but this is sending error on live server.

any idea what is this? and how can I solve it?

1
  • 2
    It'd be helpful if you pointed out WHERE line 130 is, because your snippet very obviously does not have 130 lines. But you're probably doing something like if (foo() = 37), trying to assign a value to a function, instead comparing: if (foo() == 37) Commented Apr 4, 2014 at 14:26

1 Answer 1

12

It's likely this line causing the error:

if ( !empty ( display_header_text() ) ) : ?>

As the documentation for empty() states:

Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

Sign up to request clarification or add additional context in comments.

7 Comments

Note that it says it will result in a parse error, whereas OP is getting a fatal error.
@NiettheDarkAbsol: I think the documentation is just wrong. See here: 3v4l.org/XrWMf
Fair enough - wouldn't be the first time the docs were wrong XD
@Mr.beginner: Store the return value of display_header_text() in a variable before checking it with empty(). That is $headerText = display_header_text(); if (!empty($headerText)) : ?>.
@Amal Murali Thank you so much it solve my problem also
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.