I'm trying to make hard-coded text translatable in WordPress theme.
This is the code:
<a class="btn advanced-search-btn btn-full-width" data-toggle="collapse" href="#advanced-search-filters">
<i class="houzez-icon icon-cog mr-1"></i> <?php echo houzez_option ('srh_btn_adv', 'Advanced');?>
</a>
And this is what I have tried:
<a class="btn advanced-search-btn btn-full-width" data-toggle="collapse" href="#advanced-search-filters">
<i class="houzez-icon icon-cog mr-1"></i> <?php _e houzez_option ('srh_btn_adv', 'Advanced', 'wpml_theme');?>
</a>
It gave me an error:Syntax error, unexpected T_String
I have tried to replace _e with __e and also tried esc_html__ but it give me the same error!
What I'm doing wrong?
Replace
<?php echo houzez_option ('srh_btn_adv', 'Advanced');?>
with
<?php _e(houzez_option ('srh_btn_adv', 'Advanced'));?>
Related
At the beginning I want to say that all the code presented below works well if put in right environment. I only have an issue with php in wordpress menu navigation that seems not to be able to work.
I'm trying to print user's role (there's only one role a user can have at a time) in a dropdown. PHP code:
<?php
$user = wp_get_current_user();
echo $user->roles[0]; ?>
dropdown code:
<ul id="primary-menu" class="navbar-nav ml-auto"><li class="nav-item menu-item menu-item-type-gs_sim menu-item-object-gs_sim">(Untitled)<small class="description"></small><small class="description"><div class="dropdown show"><a href="" class="nav-link">
</a><a class="nav-link btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<img src="http://ds.com/wp-content/uploads/ultimatemember/1/profile_photo-40x40.png?1561371663" class="gravatar avatar avatar-40 um-avatar um-avatar-uploaded" width="40" height="40" alt="pzo3xic" data-default="http://ds.com/wp-content/plugins/ultimate-member/assets/img/default_avatar.jpg" onerror="if ( ! this.getAttribute('data-load-error') ){ this.setAttribute('data-load-error', '1');this.setAttribute('src', this.getAttribute('data-default'));}"> pzo3xic
</a>
<div class="dropdown-menu show" aria-labelledby="dropdownMenuButton">
<h6 class="dropdown-header" href="/user/">Paid Subscriber</h6>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/profile">View Profile</a>
<a class="dropdown-item" href="/private-lessons">Private Lessons</a>
<a class="dropdown-item" href="/logout">Log Out</a>
</div>
</div></small></li>
<li class="nav-item menu-item menu-item-type-taxonomy menu-item-object-category">Lessons</li>
<li class="nav-item menu-item menu-item-type-post_type menu-item-object-page">Tests</li>
</ul>
I want it to present as below (where "Paid Subscriber" is the user's role name):
But when I replace "Paid Subscriber" with my custom shortcode "[print_user_role]" it kind of displays the text instead of the function within. Let me point out here that my shortcode works well when added into other places.
Problem:
The avatar along with dropdown are all in a code added via Shortcode in Menus plugin. This plugin (and all the others) don't support php inside.
I have tried adding a shortcode into my custom_functions.php, then invoking it by pasting [my_custom_function_sc] into the code, however it returned nothing.
I lost ideas on how to achieve this effect. Does any of you see a possible solution here?
EDIT
I think that I might actually print the user's role somewhere else within a certain block, then with jquery copy the text within the block and paste in place that interests me. Does any of you have any ideas on how to achieve this? I haven't used javascript/jQuery really.
Many thanks
Your code seems to be correct except this line --> echo $user->roles[0];
The correct code is --> echo $user->roles;
I am trying to include a php variable inside this php script that displays an html link. What i need is to include my php $row['vin'] variable in the href html link after the ? to pass a value to the page i am linking to. Top code block works but i still need that php variable, bottom is an example of what ive tried which will not work.
Works but missing my php variable:
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
Does not work:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin']">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
You've forgotten the rest of the concatenation logic. It's just a syntax error:
<td>
<?php if($row['instock'] == "Yes")
{
echo '<a href="orderForm.php?'. $row['vin'] . '">
<span class="glyphicon glyphicon-plus" aria-hidden="true">
</span>
</a>';
}
?>
</td>
An alternative to using PHP to echo out great chunks of mostly static content is to instead, drop in and out of the PHP context (ie <?php ... ?>) when necessary and use it like a templating language.
For example
<td>
<?php if ($row['instock'] == "Yes"): ?>
<a href="orderForm.php?<?= htmlspecialchars($row['vin']) ?>">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<?php endif ?>
</td>
See http://php.net/manual/control-structures.alternative-syntax.php
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id=$id"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
I have a search program that performs search via ajaX,whwre i need to embed html tag with php. Search works fine but when i click on edit button the id cant pass on another page. It shows thathttp://localhost/web/edit_news.php?id=$id. But i cant get the id=16. And error shows Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\web\edit_news.php on line 9. what is the error in my code?
Can any one help me to solve this?
you have change "edit_news.php?id=$id" to "edit_news.php?id='.$id.'". Because data in double quotes treated it like string. or you can use single quotes '. like href='edit_news.php?id=$id'.
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
just change it quote like ' to " and " to '
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>
OR
<?php
$id=16;
echo '<td><a class="btn btn-primary" href="edit_news.php?id='.$id.'"><i class="fa fa-pencil fa-fw"></i> Edit</a></td>';
?>
Change the single quote with double and double with single Like this :
<?php
$id=16;
echo "<td><a class='btn btn-primary' href='edit_news.php?id=$id'><i class='fa fa-pencil fa-fw'></i> Edit</a></td>";
?>
I have this code on my php file for navbar:
<?php if(!$session->is_logged_in()) {
echo '
<a href="login.php" role="button" aria-expanded="false">
Login <span class="label"> login to system</span> </a>
</li>';}
else
{
echo '
<a href="#!" class="dropdown-toggle" role="button" aria-expanded="false">
' . $session->user_name; . '<span class="badge bg-default">2</span> <span class="caret"></span> <span class="label">it is you</span>
</a>';
}
?>
I check if the session is set using (!$session->is_logged_in())
If it is not set I should get a login button on navbar.
If the session is set, I should get his username ($session->user_name).
On my website I have a preloader (astral-gaming.com) but after inserting this code and uploading this file, every page which had included it, isn't shows.
It's just the preloader and it doesn't go to the page.
After deleting that code, everything is fine.
What I should do?
Remove the ; after$session->user_name;
<a href="uploads/templates'.$row[0].'/index.php?id=<?php echo $row[0];?>"
class="btn btn-warning">
View
</a>
above is the button and in this button i want to give a path in which folder named templates should be like templates1 ,templates2, templates3. So the numeric value is a variable and 0to be attached with templates so that the folder can open and the index file can be run..so can any one help me with this
<a href="uploads/templates/<?php echo $row[0]; ?>/index.php?id=<?php echo
$row[0];?>" class="btn btn-warning">
View</a>
OR
<?php
echo '<a href="uploads/templates/'.$row[0].'/index.php?id='.$row[0].'"
class="btn btn-warning">
View</a>';
?>
<a href="uploads/templates<?php echo $row[0];?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>
If you are writing PHP code inside HTML, you need to wrap your code in <?php ?>.
Your code should be:
<a href="uploads/templates<?php echo $row[0]; ?>/index.php?id=<?php echo $row[0];?>" class="btn btn-warning">
View
</a>