How to change "Read more" button text on Wordpress posts - wordpress

After updating plugins, my "Read more" button on posts changed it's name. In Latvian language it was "Lasīt vairāk", while in Russian "Читать дальше". It's just in plain English. The image of how it looks now is via this link. Plugin updates basically wiped out the padding and the name of the button.
Tried modifying functions.php with
// Replaces the excerpt "Read More" text by a link
function modify_read_more_link() {
return '<a class="read-article" href="' . get_permalink() . '">Your Read
More Link Text</a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
global $post;
return '<a class="read-article" href="'. get_permalink($post->ID) . '">
Read the full article...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Tried loco translate and modifying internal translations of Elementor-related plugins. The closest I could get is that the elements is named "eael-post-elements-readmore-btn". Styling the element with CSS doesn't do anything. Padding or margin do not work. It's locked. Can anyone provide a hint?
The button should be in Latvian and Russian language, not in English.
PS. Figured that it is Elementor posts plugin related overriding functions.php and translators as well. At this moment, can't figure how to CSS this thing. Stays static.

Add this in functions.php:
function develop_custom_excerpt_more($more) {
global $post;
// edit here if you like
return '... <a class="excerpt-read-more" href="'. get_permalink( $post->ID ) . '" title="'. __( 'Read ', 'domain_name' ) . esc_attr( get_the_title( $post->ID ) ).'">'. __( 'Show more »', 'domain_name' ) .'</a>';
}
add_filter( 'excerpt_more', 'develop_custom_excerpt_more' );

Figured that it is Elementor posts plugin related overriding functions.php and translators as well. The eael-post-elements-readmore-btn was not changing in padding nor in margin because line-height which by default is set to 1 could not allow space for expansion.

Related

How to open products in new tabs when using product Shortcodes

I have used following shortcodes in the Home page to display set of products :-
[products limit="15"  orderby="menu_order"  columns="5"  category="shirt, shoe"]
However when any product image is clicked on the Home page, the specific link is opened on the same tab. I would like to open that link in a separate tab. How to achieve this?
Thanks!
Note: I am using Oceanwp as my active theme
Funny, i just had the same issue few days ago. Here's how i've solved it:
if ( ! function_exists( 'woocommerce_template_loop_product_link_open' ) ) {
/**
* Insert the opening anchor tag for products in the loop.
*/
function woocommerce_template_loop_product_link_open() {
global $product;
$link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );
echo '<a href="' . esc_url($link) . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link" target="_blank">';
}
}
Tested and works. You can just paste this into your functions.php or if you've made a custom plugin just include this at the very beginning.
You might need to add "is_home()" or "is_front_page()" to make it hit just the home page and not the whole site
Since I am using Oceanwp theme, I have to modify in different places than what is suggested by #Diego. But his answer gives me the clue for finding the solution.
This is the modification I did to make it work for Oceanwp.
if ( ! function_exists( 'ocean_woo_img_link_open' ) ) {
function ocean_woo_img_link_open() {
global $product;
$woo_img_link = get_the_permalink( $product->get_id() );
echo '<a href="' . esc_url( $woo_img_link ) . '" class="woocommerce-LoopProduct-link" target="_blank" >';
}
}

Add New “View Product” button below add to cart button in WooCommerce archives pages [duplicate]

I'd like to add a button next to "Add to Cart" on the product page that adds "-sample" to the product URL when clicked.
Example:
You're viewing Product 1's page and the URL is "http://www.example.com/shop/product-1/"
When you click on the button, it adds "-sample" to the URL
"http://www.example.com/shop/product-1-sample/"
How can I achieve this?
Thanks
For woocommerce 3+ (only):
In woocommerce 3 you will use woocommerce_after_shop_loop_item action hook instead, as the hook woocommerce_after_add_to_cart_button will not work anymore.
add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );
function add_custom_button() {
global $product;
$product_link = $product->get_permalink();
$sample_link = substr($product_link, 0, -1) . '-sample/';
echo '<a class="button alt btn-sample" href="' . esc_url( $sample_link ) .'">' . __( "Get a sample", "my_theme_slug" ) . '</a>';
}
Code goes on function.php file of your active child theme (or active theme). Tested and works.
Before woocommerce 3:
This is possible using hook woocommerce_after_add_to_cart_button to add your additional button on product pages, using this custom function:
add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );
function add_custom_button() {
global $product;
$product_link = get_permalink( get_the_id() );
$sample_link = substr($product_link, 0, -1) . '-sample/';
echo '<a class="button alt btn-sample" href="' . esc_url( $sample_link ) .'">' . __( "Get a sample", "my_theme_slug" ) . '</a>';
}
This code goes on function.php file of your active child theme or theme.
This code is tested and fully functional.
Based on this: Add a button after add to cart and redirect it to some custom link in WooCommerce
And this: PHP - How to remove all specific characters at the end of a string?
It's been a long time since the original question, but here's a recent update that works for me, WooCommerce 6.3.1:
/* WooCommerce customization */
add_action( 'woocommerce_after_shop_loop_item', 'custom_select_link', 11 );
function custom_select_link() {
global $product;
// Custom "Select" button.
echo '<a class="custom-button" href="' . esc_url( get_permalink( $product->id ) ) . '"><button class="custom-button"> </button></a>';
}
This answer cites an answer in wordpress.stackexchange.

How can I change the text of WooCommerce Bookings "Book now" button?

I am learning more and more php as i go along. I sorta get the gist of how php hooks work (actions, filters)
I was attempting to add a filter to my child functions page:
add_filter('woocommerce_booking_single_check_availability_text', 'wc_change_button_text');
function wc_change_button_text() {
return __( 'Add to cart', 'woocommerce' );
}
You could use WooCommerce filter hooks to change these, but I wouldn't recommend it because it'll take too long and create code bloat.
Here's what I would recommend: https://wordpress.org/plugins/woocommerce-multilingual/
I'm sure you may have already found a solution, but for anyone else that stumbles across this post, simply add this snippet to your child theme's functions file.
add_filter( 'woocommerce_loop_add_to_cart_link',
'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
$button_text = __("Change Text Here", "woocommerce");
$button = '<a class="book-now button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
Tested and works 5.4.1

CSS Grid Layout Issue

The following site uses the Genesis Framework and a child them (if it matters) and I'm getting a weird issue with the grid layout for the blog archive page.
Here is the page: https://foralles.com/community/
It is skipping the first column in the second row. What is weird is it isn't doing this on the second/third/etc. pages of the archive.
In further weirdness, it isn't doing this in Chrome but is in FF, Safari and IE.
I've deleted the posts before and after the empty column and nothing changes.
This also wasn't happening until recently and I'm not sure what changed.
Given that it works in Chrome and on the subsequent archive pages makes me think it is some CSS issue but I can't figure it out...any help would be greatly appreciate.
Here is my code:
<?php
/**
* Template Name: Blog
* This is your custom Archive page for the Swank Theme.
*/
//* Show page content above posts
add_action( 'genesis_loop', 'genesis_standard_loop', 5 );
//* Add the featured image after post title
add_action( 'genesis_entry_header', 'foralles_grid' );
function foralles_grid() {
if ( has_post_thumbnail() ){
echo '<div class="archive-featured-image">';
echo '<a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">';
echo get_the_post_thumbnail($thumbnail->ID);
echo '</a>';
echo '<a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">';
echo the_title( '<h2>', '</h2>' );
echo '</a>';
echo '</div>';
}
}
//* Remove the ad widget
remove_action( 'genesis_before_loop', 'adspace_before_loop' );
//* Remove author box
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
//* Remove the post meta function
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
//* Remove the post info function
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
//* Force full width content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Remove the entry title (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
//* Remove the post content
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
//* Add Page Heading and Content
add_action( 'genesis_before_loop', 'community_heading' );
function community_heading() {
?>
<h1>Community</h1>
<p>We built our Community page to share ideas, stories and inspiration. We’re sure you will find something that interests you and connects you to For Alles. Please enjoy exploring and reading. If there is anything you would like us to know please contact us. We’d love to hear what you think!</p>
<?php
}
genesis();
You need to use the min-height attribute. Edit the CSS as follows
.page-template-page_blog article.type-post, .archive article.type-post {
width: 33.33%;
float: left;
min-height: 450px;
}
This makes sure all the articles have a minimum height set, the problem arises when one item is bigger then another height wise and this takes up the area below it. This change can be made on the style.css file on line 881

Change "Read more" link in Wordpress 4.1 to prevent scroll/remove "more-X" hash

I insert read more tag this way:
Continue reading link send to /%postname%/#more-9, I need only /%postname%/.
What should I change and where? No results for "more" in functions.php (wp-incudes and theme file).
This is detailed in the codex under "Prevent Page Scroll When Clicking the More Link", and handled by applying the filter the_content_more_link:
function remove_more_link_scroll( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', $link );
return $link;
}
add_filter( 'the_content_more_link', 'remove_more_link_scroll' );
Add this to your theme's functions.php

Resources