Possible to add a read more link in an RSS Feed? - wordpress

This may be a weird or stupid question, but I have the following code (http://pastebin.com/PTFtqkvs) and I want to place a simple "read more" link after the description which links to the the article in the rSS feed - however whatever I do isn't working. Is it even possible to add this option and still conform to the rSS guidelines? This is built using a WP system to show Posts in a certain category.
Any help would be greatly appreciated.

You can hook onto feed specific hooks to add that to your feed content. Something like this in your theme's functions.php would work:
function my_super_awesome_feed_linker( $content ){
$extra = "<a href='" . get_permalink() . "'>Read More...</a>";
return $content . $extra;
}
add_filter( 'the_excerpt_rss', 'my_super_awesome_feed_linker' );
This will add a 'read more' link to all your feeds, though.
In order for this to work, you need to use a normal WordPress loop and the function the_excerpt_rss() instead of what you do in your code, echo $post->post_excerpt;. I've modified your pastebin here:
http://pastebin.com/6Y8pewhW
Also, just a word of advice, this won't really work as a template. WordPress has already sent headers by the time you've gotten to the page's template file. So you'll need to find a way to get those headers sent correctly, or to override them. The two easiest ways would be to filter the header content or to query the posts at 'wp_loaded' before headers are sent.

Related

How to Add "itemReviewed" in WP-postratings plugin

I want to set up the markup of Reviews on the site that would be in the snippet search engine displayed stars and the author of the review.
CMS site: WordPress 5.3 - Astra theme
I use the plugin: WP-Postrating (https://wordpress.org/plugins/wp-postratings/)
1.changed the type of markup in function.php using the filter as described in the plugin instructions:
add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' );
function wp_postratings_schema_itemtype( $itemtype ) {
return 'itemscope itemtype';
}
Markup is now defined as Review link
But because of the error: It is necessary to specify the value for the itemReviewed field.
Stars and the author are not displayed in the snippet of the search system.
Please give us a hint. What code should I add to function.php to add this field? And what would you like to see in this field, for example, the title of an article or manually fill in itemReviewed. Perhaps you need to add some special field to the article editor.
I would be very grateful. The employer wants to do this, I am a novice developer at https://improvecraft.com/
It's an old question and you probably figured out how to add this code. If someone still needs it, this code should work (and you can change also itemtype):
add_filter( 'wp_postratings_schema_itemtype','wp_postratings_schema_itemtype');
function wp_postratings_schema_itemtype($itemtype) {
global $post;
$title = get_the_title($post->ID);
return 'itemscope itemReviewed="' . $title . '" itemtype="http://schema.org/LocalBusiness"';
}

Give Out Wordpress post_content?

My problem is that I want give out post_content, but the output is with raw shortcodes and HTML.
I need an output with the correct translating.
A link should be a link and not a href, but only normal text with links.
When a media file is inside the post, I want to ignore this.
I don't want a big preview for my posts - only a simple one.
My output code:
$html .= '<p>'.string_limit_words($numpost->post_content, 20).'</p>';
You need to pass $numpost->post_content through the the_content filter, like so:
apply_filters( 'the_content', $numpost->post_content )
Further reading: https://developer.wordpress.org/reference/hooks/the_content/

How to replace old external links with new ones in all Wordpress posts automatically?

How to replace old external links with new ones in all Wordpress posts automatically?
The links are in [embed] codes in the posts.
http://old-232.external.link.com/folder/etc.mp4
with
http://newexternallink.com/~newfolder/folder/etc.mp4
Note: the new external link is just an IP address.
Note2: the external links are in some of the posts.
If you take a backup of your database before trying, you may try a search and replace, for example by using a tool plugin like Better Search Replace
I guess there are several other options, but this is one of the plugins which gives you a preview on what is going to change, before doing the actual replacement.
If you add more specific details on what your replacing, you may get more spesific answers as well.
You can do this pretty easy with a simple plugin. Use the WordPress filter the_content
function my_content_filter($content){
//only add text before WordPress posts
if(is_single() && is_main_query()){
//reply all occurances of the old URL with the new URL
$content = str_replace([OLD_LINK], [NEW_LINK],$content);
}
return $content;
}
add_filter( 'the_content', 'my_content_filter' );
For more on this check out my post on how to Add Text Before And After Content In WordPress . Part 5 is about replacing content in all your posts or pages.

Seo yoast plugin, breadcrumbs

This is question on the seo yoast wordporess plugin.
I have a friend who doesn't know that much about code/wordpress/etc, they have an ecommerce site built using magento and a blog using wordpress which is styled to match the main site and they use yoast seo plugin for seo etc. They have asked me to try an get the breadcrumbs working for them in a different way to what i know, from what i can see they want to add a prefix to the breadcrumbs 'home' which links to main site then renaming the blog from home to blog, for example home(main site) > blog(blog) > post.
Now i did just that in the plugin settings but they said that the schema markup wouldn't be complete and said there’s a filter hook called ‘wpseo_breadcrumb_links’ which gives access to the array of URLs and anchor text used to build the breadcrumbs, now i cant find anything on google that explains this or how to start writing it, i do know that it needs to go in the functions file.
Would it be possible to get some help on this.
Thanks in advance and very much appreciated.
Justin
I'm not sure what Schema.org markup has to do with breadcrumbs! :) Schema is used on post/page level. So, they are either oversmarting themselves or I got you wrong.
I think this sample code may be helpful:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = '<span typeof="v:Breadcrumb">Products</span> »';
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
It looks like wpseo_breadcrumb_output gives you access to the entire output instead of just the link portion. Please see this page for more details: http://wpquestions.com/question/showChrono/id/8603

Wordpress: How to pass additional Content to the blog-preview page?

For each blog-post on my wordpress-blog I'd like to have Teaxtarea where i can pass additional content for that post.
In my case that would be an unordered list which contains a quick overview of the content.
That additional content should be displayed in the preview of the post on the blog-preview-page.
My problem:
I am actually not sure on how to best add this additional content and then pass it to the preview.
Do I use wordpress' custom fields for something like this?
I'm gratefull for a push in the right direction.
Thank you,
Nils
If I understand you right, I'd take a look at "custom meta boxes" functionality - it allows you to add any type of additional input into your blog post admin area, and than display its content on front-end however you like.
There's a nice tutorial series on that topic, with example code snippets:
http://wp.tutsplus.com/series/reusable-custom-meta-boxes/
And if you'd like to display the textarea content only in preview mode, you can use appropriate conditional tag in you template file:
http://codex.wordpress.org/Conditional_Tags#A_Preview
The conditional tag is_preview returns true when a single post is viewed in Draft mode. The following will append post meta to the content when a post is being previewed:
function so16799607_preview( $content )
{
if ( ! is_preview() )
return $content;
return $content . get_post_meta( get_the_ID(), 'my_post_meta', true );
}
add_filter( 'the_content', 'so16799607_preview', 10, 1 );
You should check out Advanced Custom Fields. That's a really stable plugin that lets you create custom meta boxes in posts, pages and custom post types. That plugin does exactly what your question states. Need al little PHP to get stuff from your database, but that is as easy as:
<?php the_field(field_name);?>
And the documentation is pretty good. And if you don't like a plugin, it exports the PHP as well.
Anther tool that does the same is Pods Framework. Both powerfull extensions to any WP install in my opinion.
Hope this helps.

Resources