ntrrobng
Forum Replies Created
-
Forum: Plugins
In reply to: custom URL in Jetpack tile galleryOh missed some. Also change this:
<a border="0" href="
to this:
<a border="0" target="_blank" href="
Sorry this is horribly ugly.
Forum: Plugins
In reply to: custom URL in Jetpack tile galleryIf you want all of them to display in a new tab, look for the following in the same file:
<a href="
Replace with
<a target="_blank" href="
There will be more than one place that this occurs. If you only want it to open in a new tab if the alt text exists, it will take a bit more modifications…
Forum: Plugins
In reply to: custom URL in Jetpack tile galleryTo open a link in a new tab, you need to add a target to the link anchor in the HTML (see stackoverflow answer below), which is built in the rectangular_talavera and square_talavera functions.
https://stackoverflow.com/questions/6296013/how-can-i-open-a-link-in-new-tab-and-not-new-window
Forum: Plugins
In reply to: custom URL in Jetpack tile galleryI couldn’t find a solution to this so I modified the jetpack plugin to use the image alt-text (if it exists) instead of the image URL. There’s probably a more elegant solution but I was in a hurry and it works for my purposes.
The file that I changed: ../wp-content/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php
There are different functions for different gallery sizes (rectangular_talavera, square_talavera, etc) that all use the link, so I created a new function for the link logic:
private function get_link_url( $image ){ $alt_text = get_post_meta($image->ID, '_wp_attachment_image_alt', true); if( $alt_text != ""){ // should probably check if it's a URL with regex... return $alt_text; } $link = $this->get_attachment_link( $image->ID, $orig_file ); $search_text = "/project/"; $project_pos = strpos($link, $search_text); if($project_pos !== FALSE){// this checks if the link is already a project and truncates the URL at the project itself instead of the project picture, since this is was the primary use case in my project return substr($link, 0, strpos($link, "/", $project_pos + strlen($search_text)) + 1); } return $link; }
This needs to be used in the two functions where the link is inserted. I found it in two places: rectangular_talavera and square_talavera, where I changed
$link = $this->get_attachment_link( $image->ID, $orig_file );
to
$link = $this->get_link_url($image);
which utilizes the new function above.Voila, using the gallery image alt-text (or parent project) as the link instead of the image URL.