Automatic Source URL

A screenshot showing links that have the base URL displaying below them. So videos on youtube have "source: youtube.com" under the link title.
I like how this ended up working/looking. PHP’s parse_url function made it easy to get the base URL from resource links we’re adding via ACF. At the moment, the resource type piece that indicates if it’s video, url, audio, or document is manually added but I could see trying to do it automatically. I hesitate mainly because I could see linking to a video series that lives on a webpage. In that case, it seems video would be the right category as it’s more about the main content experience than the holder of the content.

I wrote a little filter to kick out the www. portion of links just to make them shorter. I may reconsider how it treats links that are internal to the site.

You can try it live at this site which is still being developed.

         <?php if($resources):                    
                        echo "<div class='menu-block'>
                        <ul class='resource-links'>";
                        foreach($resources as $resource){
                            $title = $resource['resource_title'];//Get the ACF data for the repeater
                            $link = $resource['resource_link'];
                            $description = $resource['resource_description'];
                            $type = $resource['resource_type'];
                            if(str_contains(strtolower($description), 'coming soon')){//if you put coming soon the in description, the link gets deactivated
                                $link = "#{$slug}";       
                            }

                            $url_source = dlinq_remove_www(parse_url($link)["host"]);//clean up source URL
                           
                            echo "
                                    <li>                                        
                                        <a href='{$link}'>
                                           <div class='inline'>
                                                <div class='resource-icon {$type}' arial-lable='Icon for {$type}.'></div>
                                           </div>
                                           <div class='inline'>
                                                {$title}
                                                <div class='resource-source'>source: {$url_source}</div>
                                                <div class='resource-description'>{$description} &nbsp;</div>
                                            </div>                                    
                                        </a>
                                    </li>
                                ";
                        }
                        echo "</ul></div>";
                    ?>
                    <?php endif;?>

2 thoughts on “Automatic Source URL

  1. I love this approach for displaying hyperlink by title but appending the source, I try to do this manually in link lists, but see how this is efficient.

Leave a Reply