How to add a custom field made with acf into the excerpt while using genesis in WP - wordpress

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)

Related

hide shortcode when one is empty

I created a shortcode to be personalised directly in product page. I was wondering if there was a way to not show the shortcode if one of them is empty ? I saw it's not recommended to work directly and check if shortcode is empty but i don't find the solution anywhere.
What i need to check (if these shortcode is empty) : [tech_img1] [tech_img2] [tech_img3] [tech_text1][tech_text2] and [tech_img3]
For example : For each product, i can enter an url img saved in this shortcode [tech_img] and text saved in this shortcode [tech_text]. However if one of the shortcode is empty (no data in it), the function custom_tech shoudn't be display in front
I used this tutorial to add and save custom field in a product page : https://remicorson.com/mastering-woocommerce-products-custom-fields
I made a custom shortcode to fuse all the shortcode i need to display
function custom_tech() {
echo do_shortcode('<div class="flextech"><img class="picfit" src="[tech_img1]" alt="tech_image1"><p class="tech-block">[tech_text1]</p><img class="picfit" src="[tech_img2]" alt="tech_image1"><p class="tech-block">[tech_text2]</p><img class="picfit" src="[tech_img3]" alt="tech_image3"><p class="tech-block">[tech_text3]</p></div>'); } add_shortcode( 'my_custom_tech', 'custom_tech');

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"';
}

Shortcode not working in custom wordpress theme

I installed a Plugin in a wordpress site which uses some shortcode (like metaslider). But when I insert the shortcode in the page it is not displayed the content of the shortcode but only the string [shortcode].
Have I to insert something in the function.php file of the theme I use? (it is a custom theme)
Thanks in advance
If only the string [shortcode] is shown instead of the actual plugin output, it seems that the output of your pages does not use the do_shortcode filter properly. Without exactly knowing what's happening, try the following:
function filter_content_example($content) {
$content = do_shortcode($content);
return $content;
}
add_filter('the_content', 'filter_content_example');
This is only a first guess. Without further investigation i could not solve that problem.

advanced-custom-fields the_field function not work in wordpress

I'm trying to use the the_field(); function in wordpress but did't work
also I tried to use the get_field(); function and same problem what I can do
<?php the_field('contact_form_short_code'); ?>
I am using advanced-custom-fields plugin the free version
the_field('contact_form_short_code') will try to get the field info from the current post in the loop. If you're not currently in a loop it will look to the current page/post.
If you want to reference a post from outside the loop you must specify the post ID, eg: the_field('contact_form_short_code', $post_id)
Hope that helps
Check if your field group location points to your template, taxonomy or custom post type, after that try to use echo to call your field.
Check this link www.advancedcustomfields.com
If you want to display the shortcode (contact_form_short_code) specified in the admin panel via a custom field (ACF), you need to use the do_shortcode(); function.
In your case, the code looks like this:
<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"]
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>

Change meta description in search result page using add_action / add_filter

I trying to change the meta description on single template and page template, and it works.
I trigger to change meta description by using add_action. But when I try to change meta description on search result page, this is not work by using add_action.
Is there any other way to to so? I need using add_action or add_filter because I will trigger the meta description from bottom of the page.
It would be easier if you added this to your header.php
<?php if (is_search())
{
//ADD SUM META DESCRIPTIONS
}
?>

Resources