Community Forums › Forums › Archived Forums › Design Tips and Tricks › Genesis Simple Share Pinterest Button
Tagged: Genesis simple share, pinterest
- This topic has 2 replies, 3 voices, and was last updated 9 years ago by
Adam Bradford.
-
AuthorPosts
-
April 17, 2016 at 7:22 am #183774
hudsonandseine
MemberIf I try to share my post on Pinterest, it automatically pulls the featured image and uses the post title for the description. Being that my featured images are horizontal with no text, they make horrible Pinterest images. I would like to configure it to be able to give people an option of what image to pin and to pull from the alt text for each image. Is there a way to change the settings to accomplish this?
http://www.hudsonandseine.comApril 17, 2016 at 11:30 pm #183808Christoph
MemberHi,
I don't think that will be possible without extensive code additions to the plugin.
You can set a special pinterest image and pinterest description with https://warfareplugins.com/
I would guess that other premium sharing plugins offer similar functionality.
April 18, 2016 at 7:37 am #183826Adam Bradford
MemberWe could add custom field support with just a few minor tweaks
Below is my patch.Basically, it updates Simple Edits to check for {network}_image, {network}_text
Returns the data if it's there, if not it continues as usual.For pinterest,
You'd add pinterest_image for the name, and the value would be the url of the image
&& pinterest_text for the text you want to showcommit c09acf1747037626cbf2e195f11ed76bb3a5a7a8 Author: admbradford <[email protected]> Date: Mon Apr 18 09:32:36 2016 -0400 Added custom field support diff --git a/lib/front-end.php b/lib/front-end.php index cc06ed9..5bd1497 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -352,10 +352,9 @@ class Gensis_Simple_Share_Front_End { $div_id = strtolower( $icon .'-'. $location .'-'. $id ); - $image = ( $image = genesis_get_image( array( 'format' => 'url', 'size' => 'full' ) ) ) ? $image : $this->get_first_image(); + $image = $this->get_share_image( $id, $icon ); - $image = $image ? $image : genesis_get_option( 'image_url', 'genesis_simple_share' ); - $description = the_title_attribute( array( 'echo' => false ) ); + $description = $this->get_share_description( $id, $icon ); //media $button = 'twitter' == $icon && ( $via = genesis_get_option( 'twitter_id', 'genesis_simple_share' ) ) ? " twitter: { via: '". str_replace( '@', '', $via ) ."' }" : ''; @@ -561,6 +560,48 @@ class Gensis_Simple_Share_Front_End { } + /** + * Get the share image for a social network + * @param int $id the post id + * @param string $network name of social media network + * @return string URL of image to share + */ + function get_share_image( $id, $network ) { + $key = sprintf( "%s_image", $network ); + $image = get_post_meta( $id, $key, true ); + + if( ! empty( $image ) && file_exists( $image ) ) + return $image; + + $args = array( + 'post_id' => $id, + 'format' => 'url', + 'size' => 'full' + ); + + $image = ( $image = genesis_get_image( $args ) ) ? $image : $this->get_first_image(); + + $image = $image ? $image : genesis_get_option( 'image_url', 'genesis_simple_share' ); + + return $image; + } + + /** + * Gets the share text for a social network + * @param int $id the post id + * @param string $network name of social media network + * @return string text to share + */ + function get_share_description( $id, $network ){ + $key = sprintf( "%s_text", $network ); + $description = get_post_meta( $id, $key, true ); + + if( ! empty( $description ) ) + return urlencode( $description ); + + return get_the_title( $id ); + } + }
Adam Bradford
Director of Web Development at Highforge
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.