Wordpress site_url repeated twice on live server - php

I got this php code form my Wordpress site, I works as expected on my localhost, but not when I moved it to live:
<li>
<a href="<?php echo get_site_url(); ?>#<?php echo $menu_id ?>">
<?php echo $menu_item->title ?>
</a>
</li>
On my localhost the url produced from the the code above looks like this:
http://localhost/wordpress/#home
But when moving to live, the exact same php code produces this url:
http://www.example.com/wordpress/#http://www.example.com/wordpress/#home
My site url field in wp_options table looks like this:
http://www.example.com/wordpress/
Why is the URL repeated twice when the site is live?

Check your wp-config.php weather WP_SITEURL is defined or not, if not then there is workaround to fix this issue by defining WP_SITEURL constant in wp-config.php like define('WP_SITEURL', 'http://www.example.com/wordpress/');

Related

Wordpress get_site_url() not working sometimes

I'm using Local by Flywheel and my local URL is: http://sarasota-soccer-club.local/. What I'm doing is adding a background image to a div in WordPress: <?php echo get_site_url(); ?>/wp-content/uploads/2023/01/hero-image.jpg. The thing is that the image sometimes doesn't show. When this happens I just replace the get_site_url() with the local URL and the background image comes back. I'm using PHPStorm and running NGINX on macOS Ventura. Any idea what's going on? Thanks.
When using image as a background, it should be located in your theme's folder (since it's part of the style) something like this:
"/wp-content/themes/your-theme/assets/img/hero-image.jpg"
If you use this approach, then you need to call it using this function:
get_template_directory_uri() (that will return the path of your theme's location):
<div class="img" style="background-image: url(<?php echo esc_url(get_template_directory_uri()) ?>/assets/img/hero-image.jpg)" >
</div>
If you want to continue using your approach you can use:
<?php echo get_home_url(); ?>
or
<?php echo site_url(); ?>
The actual problem is with your theme because sometime theme code conflict issue is happening.
Better to use get_template_directory_uri() intead of get_site_url().
<div class="img" style="style="background-image: url('<?php echo get_template_directory_uri()./foldername/imagename' ?>)"
For Reference visit https://developer.wordpress.org/reference/functions/get_site_url/
https://developer.wordpress.org/reference/functions/get_template_directory_uri/

SVG works locally, but not on remote server wordpress

This gives migraine. I just finished my website locally and moved it to my server. Now I've setup the theme with enabled SVG plugin locally and it worked like a charm. On my external server it does not (www.mantasmilka.com > single post is the one I am working on.
<?php
// check if the repeater field has rows of data
if( have_rows('info_tools') ):
?>
<div class="icon-holder">
<?php
// loop through the rows of data
while ( have_rows('info_tools') ) : the_row();
// vars
$tool_image = get_sub_field('image');
$tool_name = get_sub_field('name');
?>
<a href="#" class="<?php echo $tool_name ?>">
<svg viewbox="0 0 50 50">
<?php echo $tool_image;
echo file_get_contents($tool_image); ?>
</svg>
<img src="http://www.mantasmilka.com/wp-content/uploads/2016/05/photoshop.svg" alt="" />
<?php get_template_part(images/inline, 'http://www.mantasmilka.com/wp-content/uploads/2016/05/photoshop.svg.php'); ?>
</a>
<?php endwhile; ?>
</div>
<?php endif; ?>
I've tried numerous solutions and nothing seems to work... Does anybody have any idea what I am missing here?
Not really answer your exact question, but this is one of few question that pops up on Google search "svg works locally but not on server". Hope it help future researchers.
In my case the reason was simple to understand and fix.
Locally I was working on a file directly, but on remote that file was included. So locally I had file.php and image.svg in "root" and I called it with
<img alt="..." title="..." src="image.svg">
which worked great.
When on server the file structure was something like
[root]
+-[includes]
| +-[MY_INCLUDE_FOLDER]
| +-image.svg
| +-file.php
+-index.php
and somewhere in index.php there was this line
include_once __DIR__ . '/includes/MY_INCLUDE_FOLDER/file.php';
Now since this was not just a simple call to PHP script, with PHP output, but an entire webpage with HTML, it also had a line <base href="https://example.com/">.
This means that <img> source was actually https://example.com/image.svg instead of https://example.com/includes/MY_INCLUDE_FOLDER/image.svg.

get php file from folder using html <a href="">

My site is http:\www.xxx.com/xxx
I'm having problem to get the specific file inside a folder
The file is inside admin_pages folder under the root
The menus folder are under root too
In my i put
<a href="../admin_pages/adminAtividadesByMonthChart.php">
and it returns to http:\www.xxx.com
If i use
<a href="../../admin_pages/adminAtividadesByMonthChart.php">
Its the same...
This is my image project
any help?
You may use a constant for base url.
It may be BASE_URL
So ;
<?php
define('BASE_URL', 'http://www.example.com');
<a href="<?php echo BASE_URL;?>/admin_pages/adminAtividadesByMonthChart.php">
Good luck

How to get this Joomla Module to work correctly?

I had to move/copy a site onto a different TLD. The only thing I did not manage to get it to work was a module used on the homepage to display the latest news.
This is how the site should look: http://www.sednagroup.it/
... and this is how it looks: http://www.sednagroup.ro/
That sidebar with the image and excerpt. I can't get it to work.
Here's the module if it helps:
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<ul class="latestnews<?php echo $params->get('moduleclass_sfx'); ?>">
<?php foreach ($list as $item) : ?>
<li class="latestnews<?php echo $params->get('moduleclass_sfx'); ?>">
<a href="<?php echo $item->link; ?>" class="latestnews<?php echo $params->get('moduleclass_sfx'); ?>">
<?php echo $item->text; ?></a>
</li>
<?php endforeach; ?>
</ul>
How did you move or copy it?
The new site (.ro) is showing the expected output from the code, i.e. the title of the article wrapped in a link to the article — in fact in looks like the standard module that ships with Joomla! 1.5.x. (I'll assume 1.5 as you haven't specified your Joomla! version).
The original site (.it) is showing additional content, probably the content before the "Read More" (if one exists).
Which probably means that a template module override for the module has been created or someone has changed the core module files (bad idea by the way). I would start by:
Looking for override files in the template/yourtemplate/ directory
If you can't find an override for mod_latestnews compare the .it modules/mod_latestnews/ with the same directory on .ro
Finally if you do find that core files have been hacked may I suggested that you actually duplicate the mod_latestnews and rename it to something like mod_latestnews_extended rather than hacking the core in your .ro site.

How to turn a text called out by PHP into a link?

I'm currently using Wordpress and I have website listings that has link names as titles (eg. www.test.com, www.test2.com)
With this php code, it calls out the name of the website link:
<h3 class="list"><a class="h1" href="<?php the_permalink(); ?>"><?php the_title(); ?></h3>
Now that website has a "readmore" button and a "visit website" button. I'd like to turn the "visit website" button into a external link using PHP.
For example, the website listing is called "www.test.com". I'd like to turn the "visit website button" into an external link that will make it go to "www.test.com".
Here is my html code for the "visit website button":
<div id="visit">
Visit website
</div>
I hope someone can help.
Thanks!
I suppose you could do something like this instead
<h3 class="list"><a class="h1" href="http://<?php the_title(); ?>">Visit Website</h3>
If the_title is a valid URL starting with www (not http://), then it'll work. If they already have http:// in the title, remove that part.
Whenever you click a link you are visiting the url specified in href attribute.
For example to create a link, to go to google.com I would do this
Go to Google
So in you case you replace # with your link
<div id="visit">
Visit website
</div>
code it in php:All i can think of is this code:
<?php echo "<a href='http://www.test.com'>visit site</a>" ?>
I guess you are confused by
<?php the_permalink(); ?>
the_permalink(); calls get_permalink(); which finally provides the link.You can see its source code in wp-includes/link-template.php.

Categories