2

I have a problem with creating a proper link to the homepage of my website. I would like this code to redirect to my homepage:

<a href="/">
<div class="logo_wut">
<img style="display:inline;" src="photos/logoWUT_czarne.PNG" width="370" height="135">
</div>

Unfortunetaly it doesn't work, because it brings me to the homepage of my whole server and drupal is located in a subdirectory of the server. I tried to do this using php:

<a href="<?php print ('<front>');?>">
<div class="logo_wut">
<img style="display:inline;" src="photos/logoWUT_czarne.PNG" width="370" height="135">
</div>

but it doesn't work too. When i click on the image it appears:

Page not found The requested page "/drupal7/drupal-7.23/en/%3C?php%20print%20(%27%3Cfront%3E%27);?%3E" could not be found.

3

You should use url() function to generate a page URL. For the frontpage it is:

<a href="<?php print url('<front>'); ?>">YOUR LINK</a>

If the generated links using the url() function are not correct, you can change the $base_url variable in the settings.php

$base_url = 'http://www.yourwebsite.com/drupal7/drupal-7.23';
|improve this answer|||||
  • Unfortunetaly, this solution doesn't work either. – fragon Oct 21 '13 at 22:43
  • That's odd, Drupal should handle the url generation depending the site folder structure. I've added another solution by setting a $base_url – Mike Vranckx Oct 22 '13 at 7:29
2

There is global variable $base_path which define base URL path of the Drupal Installation.

This will at least default to '/'.

<?php global $base_path; ?>

<a href="<?php print $base_path; ?>">Home</a>

Or you can use base_path() function which will return the global variable $base_path.

<?php $path = base_path(); ?>

<a href="<?php print $path; ?>">Home</a>

Or, You can also define $base_url in your settings.php file of Drupal installation as below.

$base_url = 'http://www.example.com';

There should not be trailing slash (/) in your base url.

<?php global $base_url; ?>

<a href="<?php print $base_url; ?>">Home</a>

Kindly see that if you modify your $base_url in your settigns.php file, then you need to modify your $base_url when you transfer your file from development server to live server.

|improve this answer|||||
1

Drupal stores the homepage URL in the $base_url global.

<a href="<?php global $base_url; print $base_url; ?>">YOUR LINK</a>

Details: https://api.drupal.org/api/drupal/developer!globals.php/global/base_url/7

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.