Hi team, I would like to have the navigation links in my header editable using ACF. But when I place the acf field in the ‘a’ tag Pinegrow Dom tree and select href, the link does not take you to the page url, provided in the acf field. What am I missing? I have included a screen recording to explain the problem further.
Your felid name is wrong in PG try main_sub-menu_link
, in your video you had main_submenu_link
I can’t even calculate how much it has cost me over the years from misplaced commas, semicolons, or misspelled variable, so you’re not alone in this
I think with coding you just need another pair of eyes, especially when you’ve been staring at the problems for hours!
Unfortunately that fix wasn’t enough. I noticed that that all the set links worked if you were selecting them from the home page but if you were selecting them from a different page, it didn’t work. I thought this was because I set the acf fields from my home page so I created a global options page instead. But the issue still persists. Any ideas why?
I found the issue.
It’s to do with the code that Pinegrow generates.
When adding an ACF link for a field titled ‘main_sub-menu_link_2’, Pinegrow generates the following code:
<?php echo esc_url( get_field( 'main_sub-menu_link_2' ) ); ?>
This is acceptable if you are not needing the link to be available globally. but if you are using ACF options, the following seems to have worked for me:
<?php if( get_field('main_sub-menu_link','options') ){ ?>
<?php the_field('main_sub-menu_link','options'); ?>
<?php } ?>
I believe the significant part of the code is the ‘options’ parameter, which directs the code to be active globally. Now I have had to include this into the header.php file, which Pinegrow generates. I think we are not meant touch files that are generated by Pinegrow. How can I make the changes necessary without touching the generated files @matjaz? Thanks in advance.
@Hannah using Function action with If condition action is the way to go in this case:
<p class="mb-0" cms-function="code" cms-function-type="element" cms-function-code="the_field('main_sub-menu_link','options')" wp-if-custom="get_field('main_sub-menu_link','options')">Lorem ipsum dolor sit amet, consectetur adipiscing elit eiusmod</p>
Result:
Post Field action only works with post fields, not global ones.
This has worked beautifully. Thank you.