Changing PHP request into fixed URL. (Wordpress Template Header) - php

Very short question but it seems like i'm just to dumb.
<div class="header-content" id="header-content">
<div class="container">
<div id="logo">
<a href="<?php echo home_url(); ?>" title="<?php bloginfo('name'); ?>">
<?php
if(isset($theme_options['logo']) && isset($theme_options['logo']['url']) && $theme_options['logo']['url'] != ''){
echo '<img src="'.$theme_options['logo']['url'].'" alt="" />';
}
else{
echo '<img src="'.get_template_directory_uri().'/assets/img/placeholder/logo.png" alt="" />';
}
?>
</a>
</div>
Since there is only just one "href" in it i thought i could change this line:
<a href="<?php echo home_url(); ?>" title="<?php bloginfo('name'); ?>">
Into:
<a href="http://example.com/" title="<?php bloginfo('name'); ?>">
But after a cache clear and reload nothing changed. In case you didnt figured out what i try, its simple. I want to change the link the blog logo is leading to without changing the blog home url.

Related

Redirect WordPress Header Logo To Specific URL

I'm trying to redirect the header logo to a specific URL as well. I came across this site during my research. Please take a look at the following code and let me know exactly what modifications needs to be made to accomplish this. Thanks in advance.
<h1 class="<?php echo $class; ?>">
<a href="<?php echo esc_url(home_url('/')); ?>" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home">
<?php echo $logo; ?>
</a>
</h1>
Thanks,
Jon
Remove <?php echo esc_url(home_url('/')); ?> and replace it with your URL like so:
<h1 class="<?php echo $class; ?>">
<a href="https://example.net" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home">
<?php echo $logo; ?>
</a>
</h1>

Adding in links in Titles and Images with Custom Fields - WordPress

So my question is I need to add a link to a image and header in my wordpress site. Now I have tried to just add it next to it but nothing happens. It is using Custom Field Plugin.
Here is what the code looks like
<div class="calloutboxes">
<h2><?php echo $cbox['title']; ?></h2>
<img src="<?php echo $cbox['image']['sizes']['gallery_large'] ?>" height="<?php echo $cbox['image']['sizes']['gallery_large-height'] ?>" width="<?php echo $cbox['image']['sizes']['gallery_large-width'] ?>" alt="<?php echo $cbox['title']; ?>" />
<p>
<?php echo $cbox['description']; ?>
</p>
<a title="Read more about <?php echo $cbox['title']; ?>" href="<?php echo $cbox['read_more_url']; ?>"><i></i>Read More</a>
</div>
<?php endforeach;?>
</div>
</div>
Thanks

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.
...

If no image, display text?

I'm having a problem finding a code that will display text (<?php bloginfo('name'); ?>) when no image has been defined in the img src= (<?php echo get_option('to_logo'); ?>). This works in Firefox, of course, as a simple alt tag. But doesn't cut it in all browsers.
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
</a>
Wouldn't it be simpler just to do something like:
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?php
if (get_option('to_logo') != '') {
?>
<img src="<?php echo get_option('to_logo'); ?>" title="Logo" alt="Logo" />
<?php
} else {
echo bloginfo('name');
}
?>
</a>
This looks like WordPress. You can try to first test the image source to see if it is empty:
<a class="logo" href="<?php echo get_option('home'); ?>" title="<?php bloginfo('name'); ?>">
<?=(get_option('to_logo')) ? '<img src="'.get_option('to_logo').'" title="Logo" alt="Logo" />' : 'The alternate text'; ?>
</a>
You can try this:
if (get_option('to_logo') == '') {
echo bloginfo('name');
} else {
echo get_option('to_logo');
}

Categories