WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
How to wpseo_pre_analysis_post_content (13 posts)

  1. lwish
    Member
    Posted 9 months ago #

    Hello,

    Can anyone explain to me how the wpseo_pre_analysis_post_content should be used?

    I'm having a hard time finding documentation and it isn't quite clear what I should do.

    Yoast's own blog posts says the following:

    This filter is called wpseo_pre_analysis_post_content and takes 1 argument: a string containing the post’s content.

    I want to use this filter to include my custom fields into the page analysis

    http://wordpress.org/plugins/wordpress-seo/

  2. daveaspi
    Member
    Posted 9 months ago #

    Hey,

    I literally just had the same problem. We had a pretty complex setup but you basically do the following:

    function add_custom_content_to_analysis($content, $post)
    {
    	global $post;
    
    	if(is_admin()) {
    		if(has_sub_field('your_flexible_fields', $post->ID)) {
    			$sections = get_field('your_flexible_fields', $post->ID);
    			foreach($sections as $section) {
    				$content .= $section['your_content_field'];
    			}
    		}
    	} else {
    		return false;
    	}
    
    	return $content;
    }
    add_filter('wpseo_pre_analysis_post_content', 'add_custom_content_to_analysis');

    Hope this helps!

  3. lwish
    Member
    Posted 9 months ago #

    I'm going to check it out, thanks!

  4. lwish
    Member
    Posted 9 months ago #

    This doesn't appear to work, what should I put in if(has_sub_field('your_flexible_fields', $post->ID))

  5. AWB Collier
    Member
    Posted 9 months ago #

    Hello,

    I am trying to find exactly the same thing. A few questions:

    Where do I enter the above code? Is it in the functions.php file for my theme?

    Is the 'your_flexible_fields' where you enter css class labels to add to content in your posts to then get added into the Yoast XML Sitemap?

    Will this work outside the standard 'the_content' filters?

    I ask as I am trying to find a way to force add images and videos to the XML sitemap that are outside the standard content of posts/pages. The easiest way I can think of doing this is by adding a class element to any image I want added to the sitemap that Yoast would then hook into to add to the page XML sitemap the image is on.

  6. esmi
    Forum Moderator
    Posted 9 months ago #

    @AWB Collier: It is impolite to interrupt another poster's ongoing thread with a question of your own. It causes significant problems for the forum's volunteers and prevents us from being able to track issues by topic. Please post your own topic.

  7. AWB Collier
    Member
    Posted 9 months ago #

    Sorry, I thought this was a related issue question that was inline with exactly what the original poster was asking to do. No interruption was intended and I apologise for any rudeness, as it was unintended. I was just trying to get some help.

  8. dotkev
    Member
    Posted 9 months ago #

    I am having the same issue, and it's not related to the way I retrieve ACF info. That's not a problem.

    I can even explicitly append my keyword to the wpseo_pre_analysis_post_content output and they seem to be ignored.

    function seo_data($post_content){
      $post_content .= ' my exact focus keyword';
      return $post_content;
    }
    add_filter('wpseo_pre_analysis_post_content','seo_data');

    Any advice?

  9. nightundertaker
    Member
    Posted 9 months ago #

    Hello my site ( http://seoamk.com ) have another SEO tool. Can I delete this plugin and install SEO by Yoast without any trouble?

  10. lwish
    Member
    Posted 9 months ago #

    Hmmm, I still can't seem to get this to work, I would really like it to work though..

  11. moosch
    Member
    Posted 8 months ago #

    If you are building your own metaboxes with custom fields in, add this to your file, or if you just added the code to functions.php, add it there:

    function add_custom_content_to_analysis( $content ) {
    	global $post;
    	$custom = get_post_custom( $post->ID );
    	$custom_content = '';
    	foreach( $custom as $field )
    	{
    		$custom_content .= $field[0].' ';
    	}
    	return $content . ' ' . $custom_content;
    }
    add_filter( 'wpseo_pre_analysis_post_content', 'add_custom_content_to_analysis' );

    This should run through all custom fields in your post and add them to the content that SEO by Yoast looks at.

  12. njs
    Member
    Posted 3 months ago #

    Moosch's code is good, but...

    I found that the yoast focus keyword was actually added as a custom field to the $custom array - meaning that the Page Analysis reports the focus keyword is found (even if it does not exists in the content or acf).

    So, be sure to remove the focus keyword ['_yoast_wpseo_focuskw'] from the array first...

    function add_custom_content_to_analysis( $content ) {
    	global $post;
    	$custom = get_post_custom( $post->ID );
    	unset($custom['_yoast_wpseo_focuskw']); // ADD THIS
    	$custom_content = '';
    	foreach( $custom as $field )
    	{
    		$custom_content .= $field[0].' ';
    	}
    	return $content . ' ' . $custom_content;
    }
    add_filter( 'wpseo_pre_analysis_post_content', 'add_custom_content_to_analysis' );
  13. goxsel
    Member
    Posted 1 month ago #

    I've used at first for seo wpseo for http://gripijama.com but unfortunately I did not see a benefit

Reply

You must log in to post.

About this Plugin

About this Topic