I want wordpress post rss list featured image link
Ex:
<title>Test title</title>
<desc>Test desc</desc>
<image>imagelink</image>
I'm not using plugin.
Thanks
This will do. Add it to functions.php file:
// add the namespace to the RSS opening element
add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' );
function custom_prefix_add_media_namespace() {
echo "xmlns:media="http://search.yahoo.com/mrss/"n";
}
// add the requisite tag where a thumbnail exists
add_action( 'rss2_item', 'custom_prefix_add_media_thumbnail' );
function custom_prefix_add_media_thumbnail() {
global $post;
if( has_post_thumbnail( $post->ID )) {
$thumb_ID = get_post_thumbnail_id( $post->ID );
$details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');
if( is_array($details) ) {
echo '<media:thumbnail url="' . $details[0] . '" width="' . $details[1] . '" height="' . $details[2] . '" />';
}
}
}
Also when you add this, be sure to reset the permalinks (flush them), by going to Settings > Permalinks, and either change permalinks to default, and back to your defined settings, or just re-saving.
After that, check your feed and the media should be there.
Related
I want to modify my wp_head. I am using the Yoast plugin I want to add a new custom meta tag after the description meta tag. I try this code for add keyword tag but it's not shown after the description tag its shown in a lower position
this code
/*Display custom meta keywords or the post excerpt */
function add_custom_meta_key(){
#Single Page Meta Description
if( is_single() ){
$key = get_post_meta( get_the_id(), 'keywords', true);
if( ! empty( $key ) ){
$meta_key = esc_html($key);
echo '<meta name="keywords" content="' . $meta_key . '" />';
}
}}
add_action( 'wpseo_head', 'add_custom_meta_key', 2 );
hope you are having a wonderful day.
As far as I understand from your query and code, you are trying to add meta descriptions and meta keyword tag just one after another.
I think you should change the hook from wpseo_head to wpseo_metadesc
It will render the meta tags one after another.
I have added the code example below.
// Define the add_custom_meta_key callback
function add_custom_meta_key($wpseo_replace_vars)
{
if (is_single()) {
$key = get_post_meta(get_the_id(), 'keywords', true);
if (!empty($key)) {
$meta_key = esc_html($key);
echo '<meta name="keywords" content="' . $meta_key . '" />';
}
}
return $wpseo_replace_vars;
};
add_filter('wpseo_metadesc', 'add_custom_meta_key', 10, 1);
This code will provide the output shown in this image.
I use WooCommerce shortcode to show some products on the front page.
Like this [products limit="3" category="my-category" ids="86, 71, 54"].
The front page is a regular WordPress static page. The problem is that it doesn't show product short descriptions. If I use the code below but for is_front_page(), it shows short description of a regular WordPress post (not of the listed products).
function custom_short_description() {
if ( is_product_category() ) {
echo '<div class="custom-short-description">' . get_the_excerpt() . '</div>';
} }
add_action( 'woocommerce_after_shop_loop_item_title', 'custom_short_description', 45 );
Adding to the function
global $post;
$product = get_product($loop->post);
and using
$product->post->post_excerpt;
didn't help.
Any ideas how to show product short descriptions?
===================
Update
===================
If you create custom loops, you might want to create variables at the beginning of the loop and then use them:
$product = wc_get_product( $loop->post->ID );
$product_short_description = $product->get_short_description();
$product_url = $product->add_to_cart_url();
add_action( 'woocommerce_after_shop_loop_item_title', 'custom_short_description', 45 );
function custom_short_description() {
if (is_front_page()) {
global $product;
echo '<div class="custom-short-description">' . $product->get_short_description() . '</div>';
}
}
This should get you the outcome you're looking for.
Tried and tested WordPress 5.1.
This below code is working for post and not for category:
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array(
'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
How to modify it?
assume that all your posts are come from single.php. WordPress provides has_category() function to check if post has specific category.
So your code on single.php will need to be like something in given below
if( has_category('video') ){
the_post_thumbnail();
}
where it checks if post has 'video' category. And if it is true then the feature image will be displayed. otherwise, it can't. Hope it will be help you.
If you want to use a plugin you can use a plugin. If the plugin does not support displaying images in the rss feed you can add this in the function.php file. Something like:
function cattitlerss($content) {
$postcat = "";
foreach((get_the_category()) as $cat) {
$postcat .= ' ('.$cat->cat_name . ')';
}
$content = do_shortcode('[wp_custom_image_category onlysrc="false" size="full" term_id="123" alt="alt :)"]');
return $content;
}
add_filter('the_title_rss', 'cattitlerss');
I have created an options page in ACF Pro and Have added a image field called company logo. Now I want to remove the genesis site title. I have genesis removing the site title but when i add in the ACF call it does not work. If someone can take a look at what I have and give me some advice that would be great.
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
add_action( 'genesis_site_title', 'child_seo_site_title' );
/* Then add logo to header. */
function child_seo_site_title() {
$logo = get_field('company_logo', 'option');
if($logo) {
$output .= "<img src='". $logo['url']."' alt='". $logo['alt'] ."' />";
}
}
Should be simple but can seem to get it to work.
You're appending the image to an undefined variable, $output, and then doing nothing with it.
Output the image instead:
function child_seo_site_title() {
$logo = get_field( 'company_logo', 'option' );
if ( $logo ) {
echo '<img src="' . $logo['url'] . '" alt="' . $logo['alt'] . '" />';
}
}
I am developing a child theme of Twenty Eleven theme. There I need some customization in the blog page. I want to add a class in the place of id = "primary". How to discover which template is rendering the page?
Use the following code in your child theme's functions.php.
If you don't have it, create an empty one and use only the php opening tag (<?php).
This will print in the_content the current theme and template being displayed.
Seeing the main site page: child theme have an index.php
Seeing a single post: child theme don't have a single.php
Using a filter to add debugging to the content: check the comments
add_filter( 'the_content', 'so_13737534_print_template', 20 );
function so_13737534_print_template( $content )
{
// $template value equals to:
// /public_html/wp-content/themes/theme-name/template-name.php
global $template;
// Return normal content if seeing the backend
// or the user is not administrator
if( is_admin() || !current_user_can( 'delete_plugins' ) )
return $content;
// Split the value and build the output html
$split_path = explode( '/', $template );
$total = count( $split_path ) - 1;
$theme_and_template = $split_path[$total-1] . '/' . $split_path[$total];
$print = '<strong style="font-size:1em;background-color:#FFFDBC;padding:8px">Current = ' . $theme_and_template . '</strong>';
// Add our output before the_content
$content = $print . $content;
return $content;
}
The same can be printed as an Html comment in the <head>, using:
add_action( 'wp_head', 'so_13737534_print_template_in_head', 999 );
function so_13737534_print_template_in_head()
{
global $template;
echo '
<!--
TEMPLATE = ' . $template . '
-->
';
}