New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advanced Custom Field Integration #440
Comments
How do you integrate AFC in your regular theme? |
The theme's single.php file is using multiple the_sub_field('title') and the_sub_field('content') functions. And they are wrapped with various if statements and while loops. We're able to get the title and content outputted on the AMP pages but all the image tags being displayed are not sanitized with 'amp-img' and therefore not passing AMP's validation. |
I have this exact issue. The content from ACF is outside the "post_amp_content", which apparently means, that img elements will not be changed to amp-img, making validation fail. I have changed the AMP plugins single.php file to include |
I have this issue too. |
I also have this issue. I tried ACF-AMP but it didn't sanitize the content in repeaters |
Has anyone figured this out? I, too, am having issues with this. I would like to sanitize ACF WYSIWYG fields so that |
@kevinkonrad Can you share the code for how you are integrating ACF into your AMP post templates? |
Also have the same issue and also use sub_fields in my content :) |
@Bengolino please share the steps that I can do to replicate what you are seeing on a vanilla install. |
ACF should be fully supported as of 1.0 since the active theme's templates are encouraged to be re-used in AMP. |
@westonruter What do you mean 1.0? You comment was impossible to understand... could you explain? |
Version 1.0 of the AMP plugin should work seamlessly with ACF due to the reuse of the active theme's normal templates. |
Well it doesn't.
I think it's caused by the fact that I'm using AMP ACF and in my custom
template I am rendering a field as is.
It is rendered with the <img> tag without replacing it.
Any idea how to make it work with the AMP ACF?
It looks like the output of AMP for ACF has to go through additional
processing and it doesn't.
…On Sun, Jun 24, 2018 at 5:59 PM Weston Ruter ***@***.***> wrote:
Version 1.0 of the AMP plugin should work seamlessly with ACF due to the
reuse of the active theme's normal templates.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#440 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgiZBp8pRNR9UybYviltEQRHdZdhBoEks5t_6k3gaJpZM4Jo1ye>
.
|
If you are using the classic templating system then no, ACF won't work if your ACF output is not part of the content. Share the code for your custom template. There should be a solution involving output buffering. |
Thanks Weston,
Here is my template code, the problem is with the rendering of the
*section_content* field inside the *section_list* loop:
<?php
$introduction = get_field('introduction');
if (isset($introduction) && trim($introduction)!='' &&
trim($introduction)!='<p></p>') {?>
<div class="amp-wp-article-content">
<p><?php echo get_field('introduction'); ?></p>
<div class='topics-summary'>
<h5>In this article:</h5>
<ol>
<?php while( have_rows('section_list') ): the_row(); ?>
<?php $title = get_sub_field('section_title_h2'); ?>
<?php $reftitle = str_replace(" ", "-", $title); ?>
<li><a href="#<?php echo $reftitle ?>"><?php echo $title ?></a></li>
<?php endwhile; ?>
</ol>
</div>
<?php while( have_rows('section_list') ): the_row(); ?>
<?php $linkedpost = get_sub_field('section_linked_post'); ?>
<?php $postlink = get_permalink($linkedpost->ID); ?>
<?php $posttitle = get_the_title($linkedpost->ID); ?>
<?php $title = get_sub_field('section_title_h2'); ?>
<?php $reftitle = str_replace(" ", "-", $title); ?>
<h2><a name='<?php echo $reftitle; ?>'><?php echo $title; ?></a></h2>
<p><?php echo get_sub_field('section_content'); ?></p>
<?php if ($linkedpost != false) { ?>
<div class='section-read-more'><b>More on </b><a href="<?php echo $postlink
?>"><?php echo $posttitle ?></a></div>
<?php } ?>
<?php endwhile; ?>
</div>
<?php
}
?>
What do I need to do in order to fix this?
Thank you for the help.
…On Sun, Jun 24, 2018 at 6:26 PM Weston Ruter ***@***.***> wrote:
If you are using the classic templating system then no, ACF won't work if
your ACF output is not part of the content. Share the code for your custom
template. There should be a solution involving output buffering.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#440 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgiZHpYpAtvgx8S-zIMm_zEm9swhbWaks5t_6-LgaJpZM4Jo1ye>
.
|
OK, so assuming you have copied the <?php echo $this->get( 'introduction' ); ?> Then you need to add a add_filter( 'amp_post_template_data', function( $data ) {
ob_start();
?>
👉👉👉 PUT INTRODUCTION TEMPLATE CODE CODE HERE 👈👈👈
<?php
$content = ob_get_clean();
if ( empty( $content ) ) {
return $data;
}
$amp_content = new AMP_Content(
$content,
amp_get_content_embed_handlers( get_post() ),
amp_get_content_sanitizers( get_post() )
);
$data['introduction'] = $amp_content->get_amp_content();
$data['amp_component_scripts'] = array_merge(
$data['amp_component_scripts'],
$amp_content->get_amp_scripts()
);
$data['post_amp_stylesheets'] = array_merge(
$data['post_amp_stylesheets'],
$amp_content->get_amp_stylesheets()
);
return $data;
} ); |
Again, none of this is necessary if you just use the new theme support in the plugin. You can write templates as you do normally when you write themes. |
Thanks Weston, but the entire code I sent is the template of the post which has multiple custom fields, some of which are lists. The template is for 'post' and it has:
All of these are rendered in the template which I had sent. Could you please explain again having this in mind? Thanks a lot... What do you mean by "new theme support" - How do I use the new theme support in the ACF plugin? |
Especially I don't understand how to deal with the section_list inside the ob section in your walkthrough. |
For documentation on the new theme support in the plugin, see https://github.com/Automattic/amp-wp/wiki/Adding-Theme-Support |
Weston, this is not how I am using the templates. In addition, the way you suggested only takes into account the introduction custom field but my template includes many fields (the whole template needs to go through the AMP sanitizers...) Thanks |
I do not know. I didn't know that ACF allowed you to edit PHP code. I am not familiar enough with ACF to provide further guidance. |
This is an extension that you guys provide on your website. Don't you
provide official support for it? I am paying for it.
…On Thu, Jun 28, 2018 at 6:12 AM Weston Ruter ***@***.***> wrote:
I do not know. I didn't know that ACF allowed you to edit PHP code. I am
not familiar enough with ACF to provide further guidance.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#440 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgiZAO_DRlNApCh9ILBwP3Pi8FoFNWDks5uBEmPgaJpZM4Jo1ye>
.
|
@westonruter - I did install the latest alpha build on a test site. I can confirm that ACF fields do render in paired and native mode! 🎉 This test uses custom fields on a custom post type, enabled using the toggles in the settings menu as introduced in The original post on this thread is very out-of-date as classic/legacy-paired mode probably doesn't work as of pre- While I did have errors on my site, they were related to CSS and JS that could be solved as discussed elsewhere in our documentation. (They were related to unsupported components.) As long as you follow ACF's instructions to call its fields, there's nothing I can quickly see that is in conflict with what our plugin does. @uri3000 - I'm fairly certain you're talking about this other plugin which we do not support. |
The posts on my wordpress blog are built using AFC and I've been trying to integrate AFC into the plugin, but have had no luck.
Is there something I'm missing? Or a way that is already built out to accomplish this?
The text was updated successfully, but these errors were encountered: