Tagged: acf, post type, Shortcodes
-
AuthorPosts
-
October 16, 2018 at 3:56 pm #1022238
Hiya
I’ve been looking at altering the post format link for my blog posts so that if an ACF field exists for the post the link will redirect. I’ve found the reference in helper-post-format.php with the following but not sure where to add my ACF shortcode. Any help would be greatly appreciated.
Thanks
Richard/** * The avia_link_content_filter checks if the beginning of the post is a url. If thats the case this url will be aplied to the title. * Otherwise the theme will search for the first URL within the content and apply this URL */ if(!function_exists('avia_link_content_filter')) { function avia_link_content_filter($current_post) { //retrieve the link for the post $link = ""; $newlink = false; $pattern1 = '$^\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i'; $pattern2 = "!^\<a.+?<\/a>!"; $pattern3 = "!\<a.+?<\/a>!"; //if the url is at the begnning of the content extract it preg_match($pattern1, $current_post['content'] , $link); if(!empty($link[0])) { $link = $link[0]; $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false)); $current_post['title'] = "<a href='$link' rel='bookmark' title='".__('Link to:','avia_framework')." ".the_title_attribute('echo=0')."' $markup>".get_the_title()."</a>"; $current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1); } else { preg_match($pattern2, $current_post['content'] , $link); if(!empty($link[0])) { $link = $link[0]; $current_post['title'] = $link; $current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1); $newlink = get_url_in_content( $link ); } else { preg_match($pattern3, $current_post['content'] , $link); if(!empty($link[0])) { $current_post['title'] = $link[0]; $newlink = get_url_in_content( $link[0] ); } } } if($link) { if(is_array($link)) $link = $link[0]; if($newlink) $link = $newlink; $heading = is_singular() ? "h1" : "h2"; //$current_post['title'] = "<{$heading} class='post-title entry-title ". avia_offset_class('meta', false). "'>".$current_post['title']."</{$heading}>"; $current_post['title'] = "<{$heading} class='post-title entry-title' ".avia_markup_helper(array('context' => 'entry_title','echo'=>false)).">".$current_post['title']."</{$heading}>"; //needs to be set for masonry $current_post['url'] = $link; } else { $current_post = avia_default_title_filter($current_post); } return $current_post; } }
October 17, 2018 at 3:06 pm #1022795Hey Richard,
I think you can add your acf code after this line of code:
if($newlink) $link = $newlink;
you can add:
if( get_field( "mylink" ) ) $link = get_field( "mylink" );
Hope it helps.
Best regards,
NikkoOctober 17, 2018 at 7:38 pm #1022982Hi Nikko
I’ve added the code and included the custom field name instead “mylink” but nothing happens.
I’m not placing the ACF shortcode in the post content but instead using the column on the right of the post. Will that affect how it outputs?
Richard
October 18, 2018 at 8:02 am #1023181Hi Richard,
You can see this code below from the code you posted:
$current_post['url'] = $link;
this basically just means that it just changes the current post’s url but not the content, so it will just change the link but content is still the same.
Can you give us a link to the page where you want it to take effect? as well as give us admin access, so we can try to check the backend.
Just post the details in private content, so it’s only the moderators who can view it.Best regards,
NikkoOctober 18, 2018 at 8:30 am #1023188Hi Nikko
Ok thanks, here’s the login details so you can take a look.
Thanks
RichardOctober 18, 2018 at 3:45 pm #1023397Hi raslade,
Thanks I’m getting this in the frontend (href is an error):
<a href="Error: Function does not exist. Check name in shortcode or is function name is loaded." target="_blank">Agenda April 2016</a>
I also Appearance > Editor isn’t available. Can we request for ftp access? so we can access the files as well and try to inspect further.
Best regards,
NikkoOctober 18, 2018 at 5:56 pm #1023526Hi Nikko
Ignore the meeting agenda section, that’s another plugin i’ve been testing to replicate PDF links. FTP below
Richard
October 19, 2018 at 3:51 pm #1023971Hi raslade,
I have checked it and noticed that the code you posted above had nothing to do with the shortcode you used, that’s why nothing is happening.
The only thing I noticed is that the [php_function] shortcode that you used:<a href='[php_function name='download_report']' target="_blank">[post_title]</a></h3>
isn’t defined that’s why I could see the error in the previous post. I’m not really familiar with the plugin you’re using but I think you can instead create your own shortcode which I think you can customize better.
Best regards,
NikkoOctober 19, 2018 at 4:46 pm #1024021Hi Nikko
I’ve been testing another plugin but this is probably confusing the issue. Could you check back now.
Richard
October 19, 2018 at 5:53 pm #1024122Hi Richard,
I think that’s better.
Since you are using Blog Posts, you can override config-templatebuilder > avia-shortcodes > blog to your child theme.Best regards,
NikkoOctober 19, 2018 at 6:47 pm #1024169Thanks, however i’m still having trouble getting the ACF shortcode to register having added:
if( get_field( "mylink" ) ) $link = get_field( "mylink" );
Richard
October 22, 2018 at 6:36 am #1024679Hi Richard,
I have added a postslider folder under the shortcodes folder of your child theme and copied postslider.php from the enfold theme.
Then after this code (line 468-480):if($format == 'link') { $current_post = array(); $current_post['content'] = $entry->post_content; $current_post['title'] = $entry->post_title; if(function_exists('avia_link_content_filter')) { $current_post = avia_link_content_filter($current_post); } $link = $current_post['url']; }
I added this code:
if( get_field( 'download_report') ) { $link = get_field( 'download_report'); }
Let us know if you need further assistance.
Best regards,
NikkoOctober 22, 2018 at 10:11 am #1024758Hi Nikko
Thanks for making the change and the documents are now showing via the ACF field. I’ve added a few more posts to the page and selected the format as links but now each blog posts block only shows the same link for each post even though I have selected different attachments.
RichardOctober 22, 2018 at 3:39 pm #1024915Hi Richard,
I tried checking your site again, however I’m getting:
Error establishing a database connection
Let us know if we are able to check again your site.
Best regards,
NikkoOctober 22, 2018 at 5:01 pm #1024992Hi Nikko
Ops OK should be fine now.
RichardOctober 23, 2018 at 8:13 am #1025270Hi Richard,
Glad to hear that, I have replaced:
if( get_field( 'download_report') ) { $link = get_field( 'download_report'); }
with:
if( get_field( 'download_report', $the_id) ) { $link = get_field( 'download_report', $the_id); }
Let us know if you need further assistance.
Best regards,
NikkoOctober 23, 2018 at 11:21 am #1025342Morning Nikko
Spot on thank you so much. Excellent theme, excellent support as always.
Richard
October 23, 2018 at 2:02 pm #1025406Hi Richard,
Glad that we could help you :)
Feel free to comeback if you need further assistance.
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘Changing the URL of post format link’ is closed to new replies.