I would like to edit the yoast seo meta fields in a frontend form, is this possible?
I can populate the fields with the code below but was having trouble with the update part of it. What if the post doesn’t have existing yoast meta and is using a yoast defaults? would I need to code for a possible insert transaction?
It would be nice for the client to edit the basic seo and not interfere with the plugin operation by editing those fields directly.
If someone could steer me in the right direction or tell me if it is possible that would be great.
Thanks
function my_acf_load_value_meta( $value, $post_id, $field )
{
$value = get_field( “_yoast_wpseo_metadesc”, $post_id );
return $value;
}
add_filter(‘acf/load_value/key=field_571fd25505138’, ‘my_acf_load_value_meta’, 10, 3);
function my_acf_load_value_title( $value, $post_id, $field )
{
$value = get_field( “_yoast_wpseo_title”, $post_id );
return $value;
}
add_filter(‘acf/load_value/key=field_571fd28705139’, ‘my_acf_load_value_title’, 10, 3);
Use and acf/update_value filter and apply the same logic in reverse https://www.advancedcustomfields.com/resources/acfupdate_value/
use update_post_meta() to insert the values.
You should also using get_post_meta() when dealing with non ACF fields, event if get_field() will sometimes work.
Thanks for the help there. I did get the title and meta to update with a static value in the code at the bottom of the post.
Just having a little trouble getting the fields value from the front end form before update.
I tried a few variations of this.
function my_acf_update_value_meta( $value, $post_id, $field )
{
$field_key = “field_57205386becf2”;
$field = get_field_object($field_key);
$yoast_value = $field[‘value’];
$value = update_post_meta( get_the_ID(), ‘_yoast_wpseo_metadesc’, $yoast_value );
return $value;
}
add_filter(‘acf/update_value/key=field_57205386becf2’, ‘my_acf_update_value_meta’, 10, 3);
Working with static values:
function my_acf_update_value_meta( $value, $post_id, $field )
{
$value = update_post_meta( get_the_ID(), ‘_yoast_wpseo_metadesc’, ‘My Meta Description’ );
return $value;
}
add_filter(‘acf/update_value/key=field_57205386becf2’, ‘my_acf_update_value_meta’, 10, 3);
function my_acf_update_value_title( $value, $post_id, $field )
{
$value = update_post_meta( get_the_ID(), ‘_yoast_wpseo_title’, ‘My Meta Title’ );
return $value;
}
add_filter(‘acf/update_value/key=field_571fd28705139’, ‘my_acf_update_value_title’, 10, 3);
This should do it
function my_acf_update_value_meta($value, $post_id, $field) {
update_post_meta($post_id, '_yoast_wpseo_metadesc', $value);
return $value;
}
add_filter('acf/update_value/key=field_57205386becf2', 'my_acf_update_value_meta', 10, 3);
The topic ‘Edit Yoast Fields – Front End Form’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.