I have a link that is in the short description of a woo-commerce product. This link type is there in every product I have (different of course).
I'll need a script to automatically change the links. These are the attempts I tried so far:
WP-HideRefer
I have installed the plugin (https://wordpress.org/plugins/wp-hiderefer/), did not work. Did not change any links.
Added scripts
I used the script provided in https://anonym.to/ and put in at the end of my footer.php (before ), did not work.
Tried many other Wordpress hide referrer plugins, did not work.
Up until this point, I'm lost. I am not sure.
TL:DR
Appending text in front of every external link (link in short desc/normal desc of woocommerce product EXCEPT own website domain/link.
https://www.google.com/ is on my woocommerce product.
When user loads the product, he sees https://anonym.to/?https://www.google.com/ instead.
(https://anonym.to/? + link)
This code snippet will replace all URLs on a WooCommerce product page in both the excerpt (short description) as well as the longer description/content if you want.
It uses a regex to replace the URLs.
function so61548594_anonymize_urls($description) {
$prefix = 'https://anonym.to/?';
$description = preg_replace(
'#(<a.*?)href=["\']([^"\']+)["\'](.*?>[^>]*</a>)#i',
('$1href="' . $prefix . '$2"$3'),
$description
);
return $description;
}
add_filter('woocommerce_short_description', 'so61548594_anonymize_urls');
add_filter('the_content', function ($description) {
if (function_exists('is_product') && is_product()) {
return so61548594_anonymize_urls($description);
}
return $description;
});
Let me know if it works for you.
Related
I have a multi-currency wordpress website (using WPML plugin), I need a way to make a link to a specific product in a specified currency. I found this "hook" which can be used for that purpose: wcml_client_currency. As part of that, I added this code to my child functions.php file:
add_action( 'wcml_client_currency', 'currency' );
function currency( $current_currency ) {
$currency = isset( $_GET['currency'] ) ? esc_attr( $_GET['currency'] ) : $current_currency;
return strtoupper( $currency );
}
This works partially. I can use the URL mysite.com/?currency=EUR and arrive to the page with the currency selected to Euro. However, this code disables the currency selector widget which I have on my site. So landing on this page now does not change the currency anymore when you use the normal currency selector.
It seems to be a problem with two contradicting URL informations. i.e. with the above code, I add this "?currency=EUR" but the currency selector automatically adds this "wcmlc=GBP" to the URL. When both appear in the URL, the latter does not work.
When I use the "?currency=EUR" URL link and then browse to another page on my site, the currency stays the one I selected and the string disappears from the URL, now the normal currency switcher can be used.
Is there any code fix I can do to the above code which will display the currency requested but removes the string from the URL? or some other workaround to this problem?
I actually figured out the answer myself. In case anyone else is interested, I will post the solution:
instead of using "currency=EUR" in the URL, use "wcmlc=EUR in the URL, this will change the actual currency selector and will not overrule it. With that everything works.
The code I used:
add_action( 'wcml_client_currency', 'wcmlc' );
function wcmlc( $current_currency ) {
$wcmlc = isset( $_GET['wcmlc'] ) ? esc_attr( $_GET['wcmlc'] ) : $current_currency;
return strtoupper( $wcmlc );
}
I am trying to display a button which will direct users to a different product but the URL of this button will be the same as the current URL but will append 2 added letters to the end of the URL. For example, I am on product URL mywebsite.com/products/super-awesome-product-abc and I want the button to link to mywebsite.com/products/super-awesome-product-abcdef. I have 100 products and I will be creating more over time. I would like a dynamic solution that will display the new URL regardless of what page/product they are on. The appended characters will always be the same. I will add that the appended "abc" and "abcdef" in my example are also the product SKU. Perhaps I can use this in the solution. I am adding these buttons to the /themes/mytheme/woocommerce-bookings/booking-form/datetime-picker.php file.
I believe this works for me. I placed the below code in my themes function.php file:
add_action( 'woocommerce_before_add_to_cart_form', 'booking_lastminute_button', 35 );
function booking_lastminute_button(){
global $product;
if( $product->get_sku() ) {
echo '<p class="lastminute-button">Click to find a better product</p>';
}
below is php code that another member posted which allows for a shortcode to be inserted in the short description of every woocommerce product page (code goes into the theme's function.php file). This has worked perfectly for me, but I have one more thing I need to achieve. I assume this is simple but I have primitive knowledge of php:
How do I make the inserted shortcode into a clickable link that links to a url of my choosing? Below is the code the is currently working and needs a hyperlink:
add_action( 'woocommerce_before_add_to_cart_form', 'enfold_customization_extra_product_content', 15 ); function enfold_customization_extra_product_content() {
echo do_shortcode("[wpqr-code]");}
Try:
add_action('woocommerce_before_add_to_cart_form','enfold_customization_extra_product_content', 15);
function enfold_customization_extra_product_content() {
echo ''. do_shortcode("[wpqr-code]") . '';
}
I have a photo gallery page that is using a single page in Wordpress.
The gallery display is dynamic, and relies on a URL parameter. The parameter itself is an integer of the relating wordpress page ID. (as that's the page it's about).
Here is an example of a gallery URL:
http://www.bellavou.co.uk/gallery/?pid=238
For SEO purposes, I'm trying to get away from every possible Gallery URL combination to have the page title 'Gallery', as is set in the Wordpress page settings.
I've been trying this, which has been mentioned a few times:
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
But as I'm also using Yoast SEO plugin, I think this is over-writing it (even though I uncheck 'Force title rewrite', and keep the page title field blank). Not sure why the above function doesn't seem to work.
Within the gallery page, I'm able to show the h1 title properly, passing PHP Variables into the code, but I want to do the same to the page title, but in a way that can be done directly on the page template.
Why is it that whenever I post a question, I seem to find the answer very soon afterwards?
I read a post saying that it helps to put a wp_title function before the wp_header call, which is what I tried, and that seems to work fine.
I can edit the page title just for an individual page using the PHP page template, and using this:
$procedure = isset($_GET['pid']) ? $_GET['pid'] : '';
add_filter( 'wp_title', 'wp_title_gallery', 100 );
function wp_title_gallery($title) {
global $procedure;
if(!$procedure) {
$title = the_title();
} else {
$title = the_title(get_the_title($procedure).' ');
}
return $title;
}
get_header();
$procedure gets the URL parameter, and then the function takes that ID, and gets the associated page from it, and then prints the title of the page, into the page title hook. Lastly, the WP header is called.
(Just incase anyone comes here looking for a solution)
Does anyone know of a way to change the title of a page that is created dynamically in Wordpress? The pages in question are created dynamically via a plugin, and do not appear in the list of pages or Wordpress SEO in the admin section.
Here is an example of a page I would like to change the title of: http://www.forestlakechevrolet.com/inventory/New/
The inventory tool is maintaining the inventory of two dealerships, but only one is featured on this site. So it uses an SEO title based on the makes available at both dealerships.
Essentially, I am wondering if there is a function that I could add that would say "If URL is ... then force page title to be ***."
Does anyone know how to do this?
Thank you,
Jared Wilcox
Just use the wp_title filter
Add something like this to your theme's functions.php file:
<?php
function assignPageTitle( $title ){
global $post;
if ($post->post_name === "test") {
$title = "Title goes here";
}
return $title;
}
add_filter('wp_title', 'assignPageTitle');
?>
You may also need to change your theme's header file if the wp_title call is adding the Site Name.
BTW, WordPress questions are better asked on https://wordpress.stackexchange.com/