Display different logo in home page - wordpress - php

i would like to display a different logo in home page (with ACF).
i try with this code but it doesn't work :
<?php if(is_home()){ ?>
<?php $logo = get_field( 'logo', 'option' ); ?>
<?php if ( $logo ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo['url']; ?>" alt="" />
</a>
<?php } ?>
<?php } else { ?>
<?php $logo_footer = get_field( 'logo_footer', 'option' ); ?>
<?php if ( $logo_footer ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo_footer['url']; ?>" alt="" />
</a>
<?php } ?>
<?php } ?>
Do you have any tips ?
thank you

If you have set the homepage in Settings->Reading->Your homepage, you'll have to use is_front_page() instead of is_home().
More information here: https://wordpress.stackexchange.com/a/30389

Add This code into your php file where you want to add it.
i hope its working.
<?php
$logo = get_field( 'logo', 'option' );
$logo_footer = get_field( 'logo_footer', 'option' ); ?>
<?php if ( $logo ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo['url']; ?>" alt="" />
</a>
<?php } ?>
<?php if ( $logo_footer ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo_footer['url']; ?>" alt="" />
</a>
<?php } ?>

Related

How to displaying Custom image, text and default image logo from Redux Framework option panel

I am using Redux framework option panel to handle logo on my header.
The scenario:
Display custom logo when I upload my own logo.
Display text logo when the custom logo not active.
Display default logo when custom logo and text logo not active.
My code here:
<?php global $redux_demo; if ( isset($redux_demo['opt_header_logo']['url']) ){ ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"> <img alt="<?php echo get_bloginfo('name'); ?>" src="
<?php if( isset($redux_demo['opt_header_logo']) ){ ?>
<?php echo esc_url($redux_demo['opt_header_logo']['url']); ?>
<?php } ?>"> </a>
<?php }
else if ( isset($redux_demo['opt_header_logo']) ){ ?>
<h1> <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php if( isset($redux_demo['opt_header_text']) ){ ?>
<?php echo esc_html($redux_demo['opt_header_text']); ?>
<?php } ?>
</a> </h1>
<?php }
else { ?>
<img src="<?php echo esc_url( get_template_directory_uri() . '/images/logo.png' ); ?>">
<?php }
?>
These code only work for custom logo and default logo (scenario 1 and 3.) But did not work when I want to use text as logo.
Really appreciate for any helps.
try this
<?php
global $redux_demo;
if ( isset($redux_demo['opt_header_logo']['url']) && !empty($redux_demo['opt_header_logo']['url']) ){
?>
<img alt="<?php echo get_bloginfo('name'); ?>" src="<?php echo esc_url($redux_demo['opt_header_logo']['url']); ?>">
<?php } else if ( isset($redux_demo['opt_header_text']) && !empty($redux_demo['opt_header_text']) ){ ?>
<h1> <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php echo esc_html($redux_demo['opt_header_text']); ?>
</a> </h1>
<?php }else { ?>
<img src="<?php echo esc_url( get_template_directory_uri() . '/images/logo.png' ); ?>">
<?php } ?>

ACF if field one available show field one otherwise wordpress title

I need if else statement with the following values using ACF Plugin.
I have a field named "headline":
<?php if ( get_field( 'headline') ) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark">
<img src="<?php the_field( 'headline' ); ?>" />
</a>
<?php } ?>
Wordpress Title Code:
<a href="<?php echo esc_url(get_permalink()); ?>">
<?php echo get_the_post_thumbnail(get_the_ID(), $thumbnail_size , array('alt' => get_the_title(),'title' => '')); ?>
</a>
What I want: If field one headline is available then show field one otherwise show the second code of wordpress title
<?php $headline = get_field( 'headline'); ?>
<?php if($headline) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark">
<img src="<?php the_field( 'headline' ); ?>" />
</a>
<?php } else { ?>
<a href="<?php echo esc_url(get_permalink()); ?>">
<?php echo get_the_post_thumbnail(get_the_ID(), $thumbnail_size , array('alt' => get_the_title(),'title' => '')); ?>
</a>
<?php } ?>
Try this code:
<?php if(!empty(get_field( 'headline'))) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark">
<img src="<?php the_field( 'headline' ); ?>" />
<?php } else { ?>
<a href="<?php echo esc_url(get_permalink()); ?>">
<?php echo get_the_post_thumbnail(get_the_ID(), $thumbnail_size , array('alt' => get_the_title(),'title' => '')); ?></a>
<?php } ?>

URL redirection depending on logged in or not

I have a logo and I want it to redirect to a homepage when the user is logged in or to a register site when the user is not logged in.
Here is my code:
<strong class="logo">
<?php if (is_user_logged_in()) ?>
<a href="http://test/register/">
<?php else ?>
<a href="<?php echo home_url();?>">
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
I'm using Wordpress. It says unexpected "else".
You are not doing your if / else statements correctly:
<strong class="logo">
<?php if (is_user_logged_in()) { ?>
<a href="http://test/register/">
<?php } else { ?>
<a href="<?php echo home_url();?>">
<?php } ?>
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
if you want to use this in a way for no brackets you have to do something like this:
<strong class="logo">
<?php
if (is_user_logged_in())
echo '<a href="http://test/register/">';
else
echo '<a href="'.home_url().'">';
?>
<img id="logo_img" title="<?php bloginfo('name'); ?>" src="<?php echo $logo_path; ?>" alt="<?php bloginfo('name'); ?>">
<strong class="logo">
<?php
if (is_user_logged_in())
{
echo '<a href="http://demo.com/register-path/">';
}
else
{
echo '<a href="'.home_url().'">';
}
echo '<img src="logo-path.png"></a>';
?>
`

Making a header link in a custom Wordpress template

I have a site: www.31publishing.co.uk and want to link the header to the site, but not sure how to do it? The code for header.php is as follows:
Here is the php: http://codepad.org/ek2r2l0J
you can add link in header by replace this code with
<div id="header" style="background: url(<?php echo $header_bg; ?>)">
<div class="inner">
<div id="title_box">
<?php if (get_option('op_logo_on') == 'on') { ?>
<a href="<?php echo home_url() ?>">
<?php $logo = (get_option('op_logo') <> '') ? get_option('op_logo') : get_template_directory_uri() . '/images/logo.png'; ?>
<img src="<?php echo $logo; ?>" alt="Logo" id="logo"/>
</a>
<?php } else { ?>
<a class="site_title" href="<?php echo home_url() ?>/" title="<?php bloginfo('name'); ?>" rel="Home"><h1><?php bloginfo('name'); ?></h1></a>
<?php } ?>
</div>
with below code
<a href="www.softwaretestingawards.com"><div id="header" style="background: url(<?php echo $header_bg; ?>)">
<div class="inner">
<div id="title_box">
<?php if (get_option('op_logo_on') == 'on') { ?>
<a href="<?php echo home_url() ?>">
<?php $logo = (get_option('op_logo') <> '') ? get_option('op_logo') : get_template_directory_uri() . '/images/logo.png'; ?>
<img src="<?php echo $logo; ?>" alt="Logo" id="logo"/>
</a>
<?php } else { ?>
<a class="site_title" href="<?php echo home_url() ?>/" title="<?php bloginfo('name'); ?>" rel="Home"><h1><?php bloginfo('name'); ?></h1></a>
<?php } ?>
</div>
</a>
What do you mean by "...want to link the header to the site"?
The code you posted is the header.php that is included in every page.
It already contains a link that load the home page of your site when you click your logo or site name.
...

PHP IF, ELSE SHOW HELP?

Coming across a massive pain, is they a way I can for example say if has youtubeurl else show vimeourl?
Here is my coding
<?php $youtube_vimeo_player = get_post_meta($post->ID,'_youtube_vimeo_player',TRUE); ?>
<?php $info = $video->info("'".$youtube_vimeo_player['youtubeurl']."'"); ?>
<div class="content">
<div>
<a href="<?php echo get_permalink(); ?>" title="<?php echo $info['title']; ?>">
<img src="<?php echo $info['thumb_large']; ?><?php echo wp_get_attachment_url( $attachment->ID , false ); ?>" alt="<?php echo $info['title']; ?><?php echo $info['title']; ?>" class="thumb"/>
</a>
</div>
</div>
<?php $info = $video->info("'".$youtube_vimeo_player['vimeourl']."'"); ?>
<div class="content">
<div>
<a href="<?php echo get_permalink(); ?>" title="<?php echo $info['title']; ?>">
<img src="<?php echo $info['thumb_large']; ?><?php echo wp_get_attachment_url( $attachment->ID , false ); ?>" alt="<?php echo $info['title']; ?><?php echo $info['title']; ?>" class="thumb"/>
</a>
</div>
</div>
Any help would be more then great : )
Did you try
if ($youtube_video_url) {
//YouTube Stuff
}
else {
//Veoh stuff
}
??
If your asking how do an if statement inline style then this is how.
<? if (something == true) { ?>
<div>something</div>
<? } else { ?>
<div>something else</div>
<? } ?>

Categories