1

My current code displays an linked image on the frontend of any WP website, I would like the link to dynamically change at the end to insert the current domain only, not the full URL.

I am currently use the below code, but can't find a way to get the domain only showing dynamically at the end of a set domain. As shown below the "CURRENTDOMAINHERE" should display the current domain with out the https:// and without any directory. EG: https://example.com/currentdomain.com

<?php
/**
 * Add image to the bottom left of the frontend of the website
 */
function cwpai_add_image_to_frontend() {
    ?>
    <style>
        #image {
            position: fixed;
            bottom: 1em;
            left: 1em;
            z-index: 9999;
            width: 100px;
        }
    </style>
    <a href="https://example.com/CURRENTDOMAINHERE" id="image">
        <img src="https://imagesrc.com/image.png" alt="image">
    </a>
    <?php
}
add_action( 'wp_footer', 'cwpai_add_image_to_frontend' );
creatoz
  • 19
  • 2

1 Answers1

0
 <?php
/**
 * Add image to the bottom left of the frontend of the website
 */
function cwpai_add_image_to_frontend() {
var=dynamic_URL;

    ?>
    <style>
        #image {
            position: fixed;
            bottom: 1em;
            left: 1em;
            z-index: 9999;
            width: 100px;
        }
    </style>
    <a href="https://example.com/<? echo var; ?>" id="image">
        <img src="https://imagesrc.com/image.png" alt="image">
    </a>
    <?php
}
add_action( 'wp_footer', 'cwpai_add_image_to_frontend' );

There are many ways to link dynamic URL all of that one of way is pass that variable while your function is calling and then bind inside <a> tag. or you just set one variable and print it right after example.com

vatsal mangukiya
  • 261
  • 2
  • 14