having difficulty echo iframe with advanced custom fields wordpress - php

Hi guys this is a pretty dumb question im really bad with php and this is basically not working and outputting the wrong thing can someone please help me.
if (get_field("gallery")){
while (has_sub_field("gallery")){
if (get_row_layout() == "video"){
echo '<ul class="bxslider">';
echo '<li>';
echo '<iframe src="'.the_sub_field("videos").'" frameborder="0"></iframe>';
echo '</li>';
}
heres a screenshot of whats happening as you can see the URL is not in the iframe src

Load the_sub_field("videos") into a variable first then include that in the string you want to echo out.
$myVar = the_sub_field("videos");
echo '<iframe src="' . $myVar . '"....
Of course this will not work if you are not correctly return a string from the_sub_field("videos") so make sure that function actually returns a string.

Related

Gettext doesnt work what I'm doing wrong?

I'm making small plugin to share the post in my word-press
Everything work but I can't get a string to be translatable throw wpml.
Bear with me it's not a question about wpml,
My problem is that I can't figure how to add Get text to my code in the right way.
Here is my code:
function add_social_share_icons($content)
{
$html = "<div class='social-share-wrapper'><div class='share-on'>Share on: </div>";
global $post;
$url = get_permalink($post->ID);
$url = esc_url($url);
if(get_option("social-share-facebook") == 1)
{
$html = $html . "<div class='facebook'><a target='_blank' href='http://www.facebook.com/sharer.php?u=" . $url . "'>Facebook</a></div>";
}
I want to translate this "Share on:" the wpml use the Gettext to detect the string.
Like this <th><?php echo __('Due date:', 'themedomain'); ?></th>
I tried something like this:
$html = "<div class='social-share-wrapper'><div class='share-on'><?php _e('Share on:'); ?></div>";
But it doesn't work!
Can someone help me please?
You can't embed a function like that into a string, only simple things can be done that way. Instead, you want to concatenate which can be done in a couple of ways, but this is probably the easiest. Also, instead of _e() which echos the text, I'm using __() to just translate
$html = "<div class='social-share-wrapper'><div class='share-on'>" . __('Share on:') . "</div>";
The second parameter of __() is the text domain, same as _e()

How to echo Wordpress/PHP functions with strings

Here are two examples of what I'm referring to.
If I wanted to make an array containing images and echo it out later, and have the images refer to the home directory, I could do the following:
<?php
$get_directory = site_url();
$random = rand(0, 1);
$picture = array(
$get_directory.'/images/0.jpg',
$get_directory.'/images/1.jpg',
);
?>
And call it:
<img src="<?php echo $picture[$random];?>"></a>
I put site_url() in the $get_directory variable and it worked properly. Before I did that, I tried inserting the function directly into the array and it didn't work.
Another example that I found recently, involving echoing with a string:
<?php
$thumbnail = get_post_meta($post->ID, $img, $single = true);
$get_directory = site_url();
if (!$thumbnail) {
echo ''; } else {
echo '<img src="'.$get_directory.'/wp-content/uploads/'.$thumbnail.'">'; ?>
I needed to put the home directory site_url() function and the get_post_meta() function into variables to properly echo them out, put them in an array, or concatenate them.
I'm wondering if this is the correct way and if functions always need to be placed into variables, or if there's a correct way to do it.
I apologize in advance if this question is inappropriate or has already been asked and answered. I looked and did not find my exact question. I'm very new to the programming aspect of web development. Thank you.
site_url() takes a parameter ($path). This parameter will be appended to the site URL:
echo '<img src="'.$get_directory.'/wp-content/uploads/'.$thumbnail.'">';
Can become:
echo '<img src="' . site_url('/wp-content/uploads/' . $thumbnail) . '">';
So no: no need to store the result of site_url() in a variable each time.

Incorporating php variable into url with href attribute

I am trying to create the necessary url from this code however it is working and I am struggling to find out why.
$linkere = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linkere); ?>">'
Currently this code is producing the url: me.php?message= . But, I would like it to create the url: me.php?message=hello for example.
Thanks for helping!
You are passing $linkere to rawurlencode(). The variable is actually named $linker.
$linker = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linker); ?>">'
You have alot of syntax problems here.
first, you need to use Concatenation message='.rawurlencode($linker).'"
second your variable do not exist, it should be $linker.
Second close the tag and insert the text, in this case i used Test.
$linker = $row['message'];
echo 'Test';
Can you try this,
$linker = $row['message'];
echo 'YOUR LINK TEXT HERE';
You don't need the <? ?> and echo in your echo, it should just be:
$linkere = $row['message'];
echo 'Test';
Otherwise you are turning php on and off again to echo something within an already open instance of php in which you are already echoing.

Display Buddypress Profile Field

Using the latest version of Wordpress & Buddypress, I am trying to display a certain custom profile field in the WP header.php. I'm terrible with PHP, but this is what I have:
<?php
global $bp;
$the_user_id = $bp->loggedin_user->userdata->ID;
if (function_exists('bp_get_profile_field_data')) {
$bp_gamertag = bp_get_profile_field_data('field=Gamertag&user_id='.bp_loggedin_user_id());
if ($bp_gamertag) {
echo '<img src="http://avatar.xboxlive.com/avatar/$bp_gamertag/avatar-body.png" alt=""/>';
}
else
echo '<img src="http://avatar.xboxlive.com/avatar/xbox/avatar-body.png" alt=""/>';
}
?>
I can't quite figure out why it isn't working. The source shows the variable still in the URL.
Also, I don't think I need the $user_user_id variable, as it isn't really being used, do I? I'm following the instructions in this topic: http://buddypress.org/support/topic/how-to-get-user-profile-data/
Try :
echo "<img src='http://avatar.xboxlive.com/avatar/$bp_gamertag/avatar-body.png' alt='' />";
Notice the use of single vs. double quotes.

php simple concatenation problem

Here is a code sample of PHP function which prints HTML links. For some reason there is problem with the title attributte of the a tag(' games' isn't concatenated). For example if I have $gameCategorie = '3D' I get <a title='3D'>3D games</a> I want to get <a title='3D games'>3D games</a>
foreach($gamesCategories as $gamesCategorie){
$gameContent = $gamesCategorie.' games';
echo '<li><a title='.$gameContent.'>';
echo $gameContent;
echo '</a></li>'. PHP_EOL;
}
Ideas about improving the quality of the code and tutorials about HTML generation by PHP are also appreciated.
All valid xhtml should have attributes enclosed in speachmarks. Try this
foreach($gamesCategories as $gamesCategorie){
$gameContent = $gamesCategorie.' games';
echo '<li><a title="'.$gameContent.'">';
echo $gameContent;
echo '</a></li>'. PHP_EOL;
}

Categories