Thread Starter
bassa
(@bassa)
No one has issues saving the SEO values on Media Attachments (pdf files, etc.)?
Thread Starter
bassa
(@bassa)
Thanks for a response, man.
It seems that this issue doesn’t get a whole lot of attention, unfortunately.
So I finally decided to tackle this one today. Here is my solution:
Looks like when hitting ‘update’ on the edit media attachment page ‘wp_insert_post’ does not fire. So the ‘save_postdata’ method in the class WPSEO_Metabox (located in wordpress-seo\admin\class-metabox.php) never gets executed.
What I have done is added a new function that is a copy of the ‘save_postdata’ and I named it ‘save_attachmentpostdata’.
I then added the filter ‘attachment_fields_to_save’ to execute it.
The only issue is that this filter catches a lot more than just the post id so we needed to change the receiving argument to ‘stuff’ and extract the post id.
The code:
add_filter('attachment_fields_to_save', array( $this, 'save_attachmentpostdata' ) );
added to the __construct function
/**
* Save the WP SEO metadata for attachment posts.
*
* @param array $stuff
* @return mixed
*/
function save_attachmentpostdata( $stuff ) {
$post_id = $stuff['post_ID'];
if ( $post_id == null )
return false;
if ( wp_is_post_revision( $post_id ) )
$post_id = wp_is_post_revision( $post_id );
clean_post_cache( $post_id );
$post = get_post( $post_id );
$metaboxes = array_merge( $this->get_meta_boxes( $post->post_type ), $this->get_advanced_meta_boxes() );
$metaboxes = apply_filters( 'wpseo_save_metaboxes', $metaboxes );
foreach ( $metaboxes as $meta_box ) {
if ( !isset( $meta_box['name'] ) )
continue;
if ( 'checkbox' == $meta_box['type'] ) {
if ( isset( $_POST['yoast_wpseo_' . $meta_box['name']] ) )
$data = 'on';
else
$data = 'off';
} else if ( 'multiselect' == $meta_box['type'] ) {
if ( isset( $_POST['yoast_wpseo_' . $meta_box['name']] ) ) {
if ( is_array( $_POST['yoast_wpseo_' . $meta_box['name']] ) )
$data = implode( ",", $_POST['yoast_wpseo_' . $meta_box['name']] );
else
$data = $_POST['yoast_wpseo_' . $meta_box['name']];
} else {
continue;
}
} else {
if ( isset( $_POST['yoast_wpseo_' . $meta_box['name']] ) )
$data = $_POST['yoast_wpseo_' . $meta_box['name']];
else
continue;
}
wpseo_set_value( $meta_box['name'], sanitize_text_field( $data ), $post_id );
}
$this->calculate_results( $post );
do_action( 'wpseo_saved_postdata' );
}
added after function save_postdata
This is obviously altering the plugin’s core files and so generally I am opposed to doing that but maybe Yoast will implement something similar as a change?
Any thoughts anyone?
Thread Starter
bassa
(@bassa)
Wow, that was a complex post to throw around, mate. But thanks, I truly appreciate your dedication!
My personal reason for not diving deeper into a solution to this “problem” was actually more or less “resolved” by this statement from the generous Dan Kern (http://www.kernmedia.com/guide-to-wordpress-seo-plugin-yoast/comment-page-1/#comment-1271).
He argues that Media Attachment pages set by WordPress can be considered (easily?) thin content by Google Panda Algorithms (and likely others, on that behalf), so there was really no in-depth reason to continue on this path (making SEO-friendly pdf documents, for example).
I hope you can take some sort of value out of this statement.
Thanks!
Interesting… We are using the attachment post type for uploading a document repository of PDFs. Each repository has a page and that page lists all of the attached PDFs.
When viewing an attachment post, it displays the title, a long description and a list of other documents in the same repository with short descriptions. Last step is clicking download which serves the file for saving.
So an attachment post type for us is practically a full page of content and not really ‘thin’.
Perhaps we are going about this the wrong way though and should re-think our approach…
Oh yeah, and Yoast, what is your opinion on the value of adding SEO to Media Attachments?
Your plugin caters to it as it has the auto-generate SEO meta data for attachments capability (working) and the ability to manually set the SEO (broken).
Would you recommend that we spend the time trying to optimize these attachments?
Hope to hear from you as we will definitely appreciate your input on this one…
http://wordpress.org/extend/plugins/wordpress-seo/changelog/
“1.4.5
Bug fixes:
…
Allow saving of SEO metadata for attachments.
…
“
Great to see it fixed, shame we never got a response on this forum…