we use WordPress and Elementor to build a page. We currently have 2 different checkout systems - one for ourselves and 1 with Shopify for Affiliates.
Because of that, we have 2 "Buy now" buttons, and we display only 1, depending on a cookie "ref".
Our own checkout uses www.digistore24.com as link and the Affiliate checkout uses neuroprogrammer.myshopify.com..
The ref cookie is set from the Shopify Affiliate plugin, which also is implemented in the WordPress page.
I placed the following code to hide one of the buttons into the header.php:
<?php if(isset($_COOKIE["ref"])) : ?>
<style>
.btn-ds24{
display: none !important;
}
</style>
<?php else: ?>
<style>
.btn-shopify{
display: none !important;
}
</style>
<?php endif; ?>
My problem now is, that if I open the page with the ref code, the correct button is only visible after refreshing the page again. The cookie is placed correctly after the first load, that's why I can't explain, why it shows the wrong button at first.
You can test it yourself here:
https://biotonics.de/playlist/biotonics-vol-1/?ref=ticverdun
Embedded in the green "Jetzt bestellen" button should be the .myshopify Link, but it's the Digistore24 link.
Is there a better way to achieve my goal?
You can test for $_COOKIE & $_GET
<?php if(isset($_COOKIE["ref"]) || isset($_GET['ref'])) : ?>
<style>
.btn-ds24{
display: none !important;
}
</style>
<?php else: ?>
<style>
.btn-shopify{
display: none !important;
}
</style>
<?php endif; ?>
Without actually seeing your code first hand and the order of operations, the only thing I can pick up on is that your cookie, while being set AFTER a person visits a page, may not be set BEFORE this style is generated.
Honestly, this is a bit of a redundant way to do it. You're better off adapting the template itself to the button, rather than using a conditional style to show/hide the button. Makes for a better experience and less prone to errors.
I get that you're using Elementor, and I'm assuming that means you're building these on the fly and somewhat need to use styles, but it's not something I'd generally suggest.
A better option may be to look at a JS library like js-cookie for easy reads, and that way you cun run the test once the browser has actually built (make sure you start with 1 button always hidden, or actively build the URL to the button based on the cookie).
Still a shoddy way to do it, but a more robust, better shoddy way
I was writing a long .php website and thought about embedding kiwiirc. The issue is, I keep getting an empty frame. The problem is even worse when I figured out that iframe for kiwiirc.com itself works, but not for the full embed code (example for not working: https://kiwiirc.com/client/irc.kiwiirc.com/?&theme=basic#your_channel ). Other sites work as expected too, the only issue I appear to have with is their own embed links. If I open their link in a browser, it works. I'm trying to run it on localhost.
Example of code not working:
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<iframe src="https://kiwiirc.com/client/irc.kiwiirc.com/?&theme=basic#your_channel" style="border:0; width:100%; height:450px;"></iframe>
</body>
</html>
Kiwiirc's embed links: https://kiwiirc.com/embedding
If you run a Kiwi applet in a frame or iframe you have to enable third party cookies because the browser sees two different domains. Your domain and the domain where the cookies come from (your embedded applet)
Just a heads up, nothing wrong with the code. I installed chromium and tested it, and it worked. Usually using firefox with a lot of addons, odd thing being that all other embeds worked, and so this specific url when opened in a new tab.
I know it's not much of an answer, but it's browser's fault.
How do you link to relative links in wordpress?
For example I'm building a site onthisdomain.co.uk but the site will actually be sent live tothisdifferentdomain.co.uk.
Using the a tag brings in the full URL which I don't want as it'll cause problems when I move the sites over. Is there a php snippet I can use? I've googled it and found an image one, <img src="<?php echo get_template_directory_uri(); ?>/... " alt="" />, but could do with an anchor one
Many thanks
I'm sorry for my bad English. I hope you will understand it.
I think you are a beginner in WordPress theme development. Best of luck to you. I think you know how to use CSS. What I mean, when we use background-image to our class. we have to think where is the image is and where is my css file is. That's how we link images to css class. If I am right. Just like that in WordPress PHP we can use.
So, we can use css files in any website or any domain name. if we use like see below.
FOLDER STRUCTURE
>css->style.css
>js
>img->hello.jpg
index.php
Just imagin. If we use css class to hello.jpg
.myimg {
background-image: url('css/hello.jpg');
height: 100px;
width: 200px;
}
So now we can use this class in any domain. But that folder structure need to be same. If I am right. Simply use, get_template_directory_uri(). To more info read reference.
CODEX
Theme Development
Contact me by searching yeshansachithak in any social network. Thanks
The relative links are returned from the get_template_directory_uri() function.
It probably returns a string that looks like this : "/path/to/file.jpg"
I have no experience in wordpress but making relative links isn't specifically a php thing.
I use:
"> to link directly to a page ID.
to link to your theme root
to link to the root
I am trying to customize the links on my site that are inserted via php. The reason they are inserted via php is for checking user login and editing the log options (the links in question) depending on their status so removing them from php is a no go as far as I can see. I've tried inline and external styling, and though, if I remember correctly, it has worked in the past for other things, it just will not work for these links. Anyone have any good ideas?
Here is the (immediate) code:
$logOptions = $PM_envelope . ' home profile settings logout' ;
The styles are this:
.loginmenulinks a:link {
color:#09C;
text-decoration:none;
font-family:GeosansLight, sans-serif;
font-size:12px;
}
same for hover, etc.
I call for this in a div in the header:
<div><?php echo $logOptions; ?></div>
Why in the world is there "no way to customize" the CSS of a link that PHP generated? PHP generates HTML, HTML and CSS are on the browser side. The browser has no way of knowing what came from PHP and what didn't, so how can it discriminate against such dynamic content?
<?php echo "Text"; ?>
CSS:
.blah {color: orange;}
Suddenly, an orange link appears.
Are you forgetting to maybe specify any styles in the first place?
You may add additional classes or id's to the a-tags to gain the ability to add your stylessheets from an external resource.
However it is not a good Idea to keep such things in your PHP Code, you should use some seperation between a view and a logical layer in your application.
Furthermore you should not use but css to gain spacing, as it is not intended to do that.
Here's a challenge that I was tasked with recently. I still haven't figured out the best way to do it, maybe someone else has an idea.
Using PHP and/or HTML, create a page that cycles through any number of other pages at a given interval.
For instance, we would load this page and it would take us to google for 20 seconds, then on to yahoo for 10 seconds, then on to stackoverflow for 180 seconds and so on an so forth.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dashboard Example</title>
<style type="text/css">
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style>
<script type="text/javascript">
var Dash = {
nextIndex: 0,
dashboards: [
{url: "http://www.google.com", time: 5},
{url: "http://www.yahoo.com", time: 10},
{url: "http://www.stackoverflow.com", time: 15}
],
display: function()
{
var dashboard = Dash.dashboards[Dash.nextIndex];
frames["displayArea"].location.href = dashboard.url;
Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
setTimeout(Dash.display, dashboard.time * 1000);
}
};
window.onload = Dash.display;
</script>
</head>
<body>
<iframe name="displayArea" width="100%" height="100%"></iframe>
</body>
</html>
Use a separate iframe for the content, then use Javascript to delay() a period of time and set the iframe's location property.
When you are taken to another site (e.g. Google) control passes to that site, so in order for your script to keep running, you'd need to load the new site in a frame, and keep your script (which I'd imagine could most readily be implemented using Javascript) in another frame (which could be made very small so you can't see it).
I managed to create this thing. It's not pretty but it does work.
<?php
# Path the config file, full or relative.
$configfile="config.conf";
$tempfile="tmp.html";
# Read the file into an array
$farray=file($configfile);
# Count array elements
$count=count($farray);
if(!isset($_GET['s'])){
$s=0;
}else{
$s=$_GET['s'];
if($s==($count-1)){ # -1 because of the offset in starting our loop at 0 instead of 1
$s=0;
}else{
$s=$_GET['s']+1; # Increment the counter
}
}
# Get the line from the array
$entry=$farray[$s];
# Break the line on the comma into 2 entries
$arr=explode(",",$entry);
# Now each line is in 2 pieces - URL and TimeDelay
$url=strtolower($arr[0]);
# Check our url to see if it has an HTTP prepended, if it doesn't, give it one.
$check=strstr($url,"http://");
if($check==FALSE){
$url="http://".$url;
}
# Trim unwanted crap from the time
$time=rtrim($arr[1]);
# Get a handle to the temp file
$tmphandle=fopen($tempfile,"w");
# What does our meta refresh look like?
$meta="<meta http-equiv=\"refresh\" content=\"".$time.";url=index.php?s=".$s."\">\n";
# The iframe to display
$content="<iframe src =\"".$url."\" height=\"100%\" width=\"100%\"></iframe>";
# roll up the meta and content to be written
$str=$meta.$content;
# Write it
fwrite($tmphandle,$str);
# Close the handle
fclose($tmphandle);
# Load the page
die(header("Location:tmp.html"));
?>
Config files looks like (URL, Time to stay on that page):
google.com,5
http://yahoo.com,10
Depends on your exact requirements. If you allow JavaScript and allow frames then you can stick a hidden frame within a frameset on your page into which you load some JavaScript. This JavaScript will then control the content of the main frame using the window.location object and setTimeout function.
The downside would be that the user's address bar would not update with the new URL. I'm not sure how this would achievable otherwise. If you can clarify the constraints I can provide more help.
Edit - Shad's suggestion is a possibility although unless the user triggers the action the browser may block the popup. Again you'd have to clarify whether a popup is allowable.
Create a wrapper HTML page with an IFrame in it, sized at 100% x 100%. Then add in some javascript that changes the src of the IFrame between set intervals.
I think it would have to work like gabbly.com, which sucks in other websites and displays them with its own content over it.
Once you read the other site in and were ready to display it, you couldn't really do it "in PHP"; you would have to send an HTML redirect meta-tag:
<meta HTTP-EQUIV="REFRESH" content="15; url=http://www.thepagecycler.com/nextpage.html">
Or you could use Javascript instead of the meta-tag.
This is not doable in a PHP script, unless you want to edit the redirect.... PHP is a back end technology; you're going to need to do this in Javascript or the like.
The best you're going to do, as far as I know, is to create a text file on your web server and load a different HTTP address based on time out of that text file, then redirect the browser to the site found in that text file.
The first solution that jumps to mind is to do this in a frameset. Hide one of the frames, and the other display the pages in question. Drive the page transitions with Javascript from the hidden frame.
function RefreshFrame()
{
parent.VisibleFrame.location.href = urlArray[i];
i++;
if(i < urlArray.length) SetTimeout("RefreshFrame()", 20000);
}
var i = 0;
var urlArray = ['http://google.com','http://yahoo.com', 'http://www.search.com'];
RefreshFrame();
In this example the Javascript would be in the hiddend frame, and you would name your visible frame "VisibleFrame".
Disclaimer: I just wrote this code in the comment window and have not tested it
You could do this with JavaScript quite easily. It would help to know the deployment environment. Is it a kiosk or something?
For the JavaScript solution, serve up a page that contains a JavaScript that will pop open a new browser window. The controller page will then cause the new browser window to cycle through a series of pages. That's about the simplest way to do this that I can think of.
Edit: Agree with Simon's comment. This solution would work best in a kiosk or large, public display environment where the pages are just being shown without any user interaction.
The theory behind the request is basically the ability to cycle through web page dashboards for various systems from a "kiosk" PC. I oversee a data center and we have several monitor systems that allow me view dashboards for temps, system up time, etc etc.
The idea is load a page that would cycle from dashboard to dashboard remaining on each for an amount of time specified by me, 1 minute on this board, 30 seconds on the next board, 2 minutes on the next and so on.. Javascript is absolutely allowable (though I have little experience with it). My mediums of choice are PHP/HTML and I'm not seeing a way to make this happen cleanly with just them..
There's a bunch of ways you can do this, iv written several scripts and tools with everything from JS to Ruby
In the end It was much easier to use http://dashboardrotator.com . It handled browser restarts, memory allocation and accidental window closure for me with a nice simple GUI.