Customize the search results page in a Wordpress Genesis child theme - wordpress

I am using Wordpress and the Genesis framework for a site. I'm using a child theme (Ayoshop - not that it matters much) for the theme. I would like to customize the search results page by removing the 'post info' area where it shows the date, author, and 'leave a comment' link, and instead show the featured image for that post. The theme is using the search.php page from the Genesis theme, so I'm not really sure how to proceed in how to customize it.
Here is the code from the Genesis theme search.php:
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* #since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();

It actually did matter that it was the Ayoshop theme, there was a custom filter that was added in a file called theme-tweaks.php that removed the original post info and added a custom post info, so I needed to remove that custom action.
All of the changes were done in the functions.php file.
I made sure to remove the genesis_post_info, and then removed the custom action that Ayoshop added.
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_before_post_content', 'ayo_post_info' );
I then added an action to add the image to the post.
add_action ( 'genesis_before_post_content', 'jl_post_info' );
function jl_post_info()
if ( has_post_thumbnail() ) {
printf( '<div class="post-info">' . get_the_post_thumbnail() . '</div>');
}
}

Related

Change "Backorder allowed" text on cart and checkout

I have managed to change the "backorder allowed" text on catalog and product pages using this solution.
However, I would also like to change the "backorder allowed" text on cart page (and possibly on checkout, though I haven't seen it on checkout). The accepted solution for a similar question doesn't work (anymore).
Adding this to my functions.php worked for me:
/* --- Out of stock (Backorder) message ON CART PAGE --- */
function custom_cart_item_backorder_notification( $html, $product_id ){
$html = '<p class="backorder_notification">' . esc_html__( 'My custom text', 'storefront' ) . '</p>';
return $html;
}
add_filter( 'woocommerce_cart_item_backorder_notification', 'custom_cart_item_backorder_notification', 10, 2 );

Add blocks to custom location on shop page?

On my woocommerce shop page I want to remove the description/blocks from the all-in-one woocommerce product grid block. Then add them back above it separately for layout reasons.
So I've removed the description like this:
remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
Then I thought I could just add it back in with a shortcode block in the archive-product.html template.
add_shortcode('shop_description', 'woocommerce_product_archive_description');
The problem is, this adds it to the very top of document even before the <html> tag, instead of where I put the shortcode block...
I realised the woocommerce_product_archive_description function uses echo and to make it work with a shortcode it needs to instead use return.
So I made a new function for the shortcode and boiled it down to be:
$shop_page = get_post( wc_get_page_id( 'shop' ) );
$allowed_html = wp_kses_allowed_html( 'post' );
$description = wc_format_content( wp_kses( $shop_page->post_content, $allowed_html ) );
if ( $description ) {
return $description;
}

Override WooCommerce Shop Site Breadcrumb with Yoast SEO Breadcrumb

I tried to remove the WooCommerce Breadcrumbs with this code:
add_action( 'init', 'remove_wc_breadcrumbs' );
function remove_wc_breadcrumbs() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
...which works.
After that I activated the Yoast Seo Plugin Breadcrumbs an placed this code in my theme header.php
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
...which also works.
The problem appears when I navigate to my "shop-site" which I defined in the WooCommerce settings. The full breadcrumb looks like this
Home > Product
Note: The Page name in WordPress for the "shop-site" is "Test" (not "Product").
I want to override the "Product" in something different. I tried to override it by defining a custom breadcrumb title in the advanced Yoast settings on the wordpress "shop-site" page but it didn't seems to work. Overriding works if the page isn't defined as the "shop-site" in the WooCommerce settings. So I guess some function overwrites the Yoast Breadcrumb override but I can't figure out which function does this.
The same problem appears when I navigate to a single product. Breadcrumb looks like this
Home > Product > Product Name
Again I want to rename the "Product" (only the second crumb here) into something different.
Can someone solve this mysticism?
I fixed it with this code:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = 'rel="v:url" property="v:title">Product</a>';
$to = 'rel="v:url" property="v:title">New Title</a>';
$output = str_replace( $from, $to, $output );
}
elseif ( is_shop() ) {
$from = '<span class="breadcrumb_last">Products</span>';
$to = '<span class="breadcrumb_last">New Title</span>';
$output = str_replace( $from, $to, $output );
}
return $output;
}
I wonder if there wouldn't be an easier way to change the first "product" into sth like "product category"...
Have you tried in wp-admin:
Go to "Yoast"
Then "SEO settings"
Then "Breadcrumbs" and adapt taxonomies (eg: product > category).

Having two RSS Feed URLs for WordPress

I am using MailChimp for my self hosted WordPress blog. MailChimp fetches RSS feeds for it's email templates. I want to add small thumbnail with excerpts in RSS feed so that they appear on MailChimp's email template but I do not want to modify the original RSS feed URL. I want to have a different URL for feeds modified for MailChimp like this: mysite.com/mailchimpfeed where as the original mysite.com/feed remains unchanged.
What will be the best way to do this?
Basic MailChimp feed:
Here's one simple idea:
/**
* Basic MailChimp feed
*
* Example: domain.com/mailchimpfeed
*/
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'do_feed_rss2' );
}
add_action('init', 'mailchimp_feed' );
to reuse the native RSS2 feed, under a different url.
MailChimp feed with featured images:
If we want to add the featured images to the MailChimp feed, we can use:
/**
* MailChimp feed with featured images
*
* Example: domain.com/mailchimpfeed
*/
add_action('init', 'mailchimp_feed' );
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'mailchimp_feed_template' );
}
function mailchimp_feed_template()
{
add_action( 'rss2_item', 'mailchimp_media_item' );
add_action( 'rss2_ns', 'mailchimp_ns' );
do_feed_rss2();
}
function mailchimp_ns()
{
print 'xmlns:media="http://search.yahoo.com/mrss"';
}
function mailchimp_media_item()
{
if( has_post_thumbnail( get_the_ID() ) )
$image = array_shift( wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ) ) );
else
$image = sprintf( '%s/default.jpg', get_site_url() );
printf( '<media:content url="%s/default.jpg" medium="image" />', $image );
}
We can then modify the featured image size to our needs and the default image if there's no one set.
Flush rewrite rules once to activate:
In both cases we just have to remember to flush the permalinks settings to activate the custom MailChimp feed.
--
Hope this helps.

Replace author url with different one (wordpress)

There are 3 authors in our company blog, each author has own site url in profile settings:
Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/
the links for profiles are:
http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/
I need to replace a link to Admin's page, so, if there is <?php the_author_posts_link(); ?> tag on some page, and the author is Admin, the link must be http://site.com/company/ instead of http://site.com/author/Admin/.
How can I do that?
It looks like the the_author_posts_link function just calls get_author_posts_url to get the link, which passes the link through the author_link filter before returning it. In your theme's functions.php, you could add something like this (untested):
add_filter( 'author_link', 'admin_author_link', 10, 3);
function admin_author_link($link, $author_id, $author_nicename) {
if( $author_id==1 ) {
$link = 'http://site.com/company/';
}
return $link;
}
I think the least heartburn would be wordpress > the_author_meta.
Have each user add their url in the wordpress user profile, as you have done. Then in your theme's functions.php use the_author_meta('user_url'). Remember this will echo the url. To use it as a variable use get_the_author_meta('user_url').
Here is how we did it with the twenty ten theme, this is in functions.php
function twentyten_posted_on() {
printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
'meta-prep meta-prep-author',
sprintf( '<span class="entry-date">%3$s</span>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_the_author_meta('user_url'), //changed from get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ),
get_the_author()
)
);
}
That's URL rewriting with .htaccess, which is possible by editing the .htaccess by hand.
But easier for a beginner with a plugin such as http://wordpress.org/extend/plugins/redirection/ which seems like it will do what you need.
You can do this using http rewrites.
I also needed author URL to a different page.
My site is on WordPress and I use oxygen.
I went to my blog page template where I entered the author which is selected dynamically.
there is an option to link the author's name to the archive page or the author's website.
I selected the author's website. Then went to the users on WordPress and went to the authors and added the page I wanted to actually go to as their website.

Resources