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"';
}
Related
I want to take the text from an custom field made with acf, and put it into the excerpts shown the posts shown on the front page. I am using genesis, and I think I have to do "remove_action" and "add_action" to do this, but I can't figure out how to do it.
You can try a filter that WordPress has called the_excerpt
add_filter('the_excerpt', 'your_function_name');
function your_function_name($excerpt) {
$my_acf_field = the_field('my_acf_field');
return $my_acf_field . ':' . $excerpt;
}
This would append the acf field string in the beginning of the excerpt. If you want this to apply only on the front page, you can only add this code in your front-page.php file OR you can put the above code in your functions.php and use the Wordpress conditional is_front_page() in the function code above.
(This code is untested)
I am writing a Wordpress plug-in that creates several Custom Post Types (CPT). For they have their own custom fields, that need to be displayed in the search results, I need to customize the search results output.
Do I need to write my own theme for that or is there a hook (or other way) to solve this in my plug-in code?
You could hook into get_the_content and get_the_excerpt filters and test with is_search() to see if you should alter the returned value or not.
Not tested, but this is the idea:
add_filter( 'get_the_excerpt', 'my_search_excerpt' );
add_filter( 'get_the_content', 'my_search_excerpt' );
function my_search_excerpt( $content ) {
if ( is_search() ) {
$content = 'This is a search excerpt for ' . get_the_title();
// maybe add a read more link
// also, you can use global $post to access the current search result
}
return $content;
}
I see four possibilities:
Create a new (child) theme
Override the search template using filters (template_include)
Use client-side code to modify the appearance (CSS / JavaScript, poor workaround)
Hook the_content or the_excerpt
The easiest way might be to copy the search.php file of your installed theme and modify it to fulfill your needs. You can then hook it in using the first or second way. The first requires you to create a child theme, the second to create a plugin. The latter might be more complex so I would suggest to create a theme (take a look at template files of child themes for an explanation).
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
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.
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.