Support

Account

Forum Replies Created

  • I just sent an email to Elliot about this issue. Don’t know if he will reply, but it is worth trying it.

  • Maybe Elliot (Mr. ACF) can have a look at this, because this is very important to a lot of ACF Pro users out there.
    For now, I’ll stay away from the 3.x Yoast plugin until someone comes with a plugin or JavaScript to replace the “wpseo_pre_analysis_post_content” filter.

  • Ok,

    Figured this one out myself.
    By default WordPress doesn’t protect custom fields, and as such, also custom fields generated by ACF.
    To work around this, all you have to do is wrap this simple if statement around your ACF code in a template file:

    if ( ! post_password_required() ) {
       //All of your code goes here
    }
    

    By magic, WordPress asks the visitor of the page for the password before showing your ACF fields.

  • Hi Websydaisy,

    I’m running into the same issue.
    Can you explain how you fixed this one, maybe with a code-example?
    (The provided code-examples from Thomask are great, but I just don’t understand what to do and/or how to implement these…)

  • Hi John,

    You made this very clear, and believe it or not, I’m one of those designers (although I try to keep away form text in images, there are often better/smarter ways to do that with HTML and CSS).
    But as I understand what you are trying to do, I think RICG is too limited.
    On the other hand, I’m very interested in your approach with ACF.
    I’ve done something similar in the past, but that was completely done in CSS with background images and before I knew about ACF. Not a very friendly solution, and every time the client wanted a new image, I had to dig into that CSS to make it happen.

  • John,
    The RICG plugin does not let you specify any image size or crop by itself. It takes the predefined image sizes (small, medium, full) and custom image sizes to do his work. It’s sole purpose is to deliver the image of a given size that fits within the area defined in HTML, taking retina/hi-dpi screens into account.
    Because you can create your own image sizes with the add_image_size function in your functions.php, you can also specify how to crop these images. You should check the WordPress Codex to see what possibilities this function offers: https://developer.wordpress.org/reference/functions/add_image_size/
    If you need more advanced sizing and/or cropping you should check other alternatives.

  • Scorch,

    I don’t know if you figured this one out yet, but there is an amazing plugin called ‘RICG Responsive images’. And that plugin works great with ACF.
    After installing the plugin, all you have to do in your template is:

    
    $image = get_field('your-image-field');
    $size = 'medium'; // (thumbnail, medium, large, full or custom size)
    if( $image ) {
         echo wp_get_attachment_image( $image, $size );
    }
    

    (Make sure to set the return value of your image field in ACF to ‘Image ID’.)

    This code returns the appropriate <img /> tag including all parameters you need (srcset).

  • I found a workaround with the ‘Fluid Video Embeds’ plugin.
    This plugin also uses shortcodes, so I’ve put the shortcode in my template:

    
    $row_video = $select_row['movie'];
    if (!empty($row_video)):
    echo '<div class="video-container">';
    echo do_shortcode('[fve]'. $row_video .'[/fve]');
    echo '</div>';
    endif;
    

    This works, but I would like to see it working directly from ACF without the use of an extra plugin.
    Any suggestions?

  • How will these and other YoastSEO related approaches work out when Yoast releases their new version of the plugin, somewhere in November. They are going to remove a lot of filters in favour of faster page analysis, one of these is the ‘wpseo_pre_analysis_post_content’ filter and that one is used by a lot of ACF developers.
    Can someone from the ACF team comment on this?

    This is what Yoast is going to do:
    https://yoast.com/yoast-seo-breaking-api-changes/

  • Paul,
    I just came across this article on Yoast’s website:
    http://kb.yoast.com/article/131-images-in-the-xml-sitemap

    Maybe it wil make you understand a bit more on how WordPress handles attached images and how Yoast deals with them.

  • Paul,
    Good question, but I don’t know (yet).
    But what puzzles me is how Yoast ‘looks’ at images in the first place.
    I know that Yoast checks the featured image of a post or page to see if the so-called ‘alt-text’ has the Focus Keyword in it you’ve set in Yoast’s interface.
    But Yoast doesn’t check this with attached images to a post or page, as far as I know.
    This means, that if you add images to a post or page with an ACF (repeater) field, these images get attached, but Yoast won’t check them.

    I think you should check Yoast’s documentation on this subject.
    And if you have found out a way on how to let Yoast look at attached images, I really like to know how you did it.

  • John,

    Thanks for your reply.
    I got it to work thanks to your little code-snippet.
    The only thing I changed was the populating of the array in the foreach loop:
    $term_names[] = $term->name;
    By adding these square brackets you ‘tell’ the array to add the new value instead of overwriting it, which is the case if you don’t add those square brackets.

  • The exact code I’ve put into my ‘functions.php’ looks like this:

    
    add_filter( 'wpseo_pre_analysis_post_content', 'filter_yoasts_wpse_119879', 10, 2 );
    
    function filter_yoasts_wpse_119879( $content, $post )
    {
    	if( have_rows('project_page') ):
    	     // loop through the rows of data
    	    while ( have_rows('project_page') ) : the_row();
    	        if( get_row_layout() == 'intro' ):
    	        	$field1 = get_sub_field( 'text' );
    			endif;
    	        if( get_row_layout() == 'in-depth' ):
    	        	$field2 = get_sub_field( 'in_depth' );
    			endif;
    	    endwhile;
    	endif;
        $fields = $field1 . ' ' . $field2;
        return $content . $fields;
    }
    

    As you can see, my Flexible Layout is called ‘project_page’.
    The first ‘while’ statement checks if there are any rows, and if so, get the one with the names ‘intro’ and ‘in-depth’, and put the content (‘text’ and ‘in_depth’) of the corresponding sub fields in a variable labeled $field1 and $field2.
    The last thing I do is combine these two variables into one ($fields) and return that.
    I’m not a PHP guru, absolutely not. But looking at different pieces of code I came up with this one. I do not know if it is very ‘clean’ or efficient PHP-code, but it works (for me)
    Actually, this function is based on the one you posted earlier.

  • I’ll check that one out.
    It looks as if it should work (it looks a little like my solution, but more complex). But my guess is that this one won’t work on a ‘Flexible Layout’, because you have to target the sub fields (rows > layouts > sub_fields) to get the correct content.
    Say you have a Flexible layout by the name of ‘project_content’, and a row where the actual content goes into is called ‘content’ and the actual content has the field name ‘text’, you have to target that one as:

    
    if( have_rows('project_content') ):
        while ( have_rows('project_content') ) : the_row();
            if( get_row_layout() == 'content' ):
    	    $custom_content = get_sub_field( 'text', $post->ID );
    	endif;
        endwhile;
    endif;
    

    (or something like that…)

  • I just combined two or more fields into 1, and that worked!
    So you have to write something like this:

    
    add_filter( 'wpseo_pre_analysis_post_content', 'filter_yoasts_wpse_119879', 10, 2 );
    
    function filter_yoasts_wpse_119879( $content, $post )
    {
        $field1 = get_field( 'text', $post->ID );
        $field2 = get_field( 'more_text', $post->ID );
        $fields = $field1 . ' ' . $field2;
        return $content . $fields;
    }
    
Viewing 15 posts - 26 through 40 (of 40 total)