Home Support General HivePress Share URL of listing

Share URL of listing

  • Author
    Posts
  • Aizen

    Hi Ihor,

    Is it possible to create an button that can share a listing URL to an e-mail address? If so do you have any pointers on the best way of doing this? I’ve been trying to create it through a text attribute with HTML MailTo code without much success for some reason 🙁

    Thanks,

    A

    sherwinramnarine

    Hi Aizen, I use Sumo on my directory (not on HivePress) that includes lots of sharing options for listings, including sharing by email. They offer a free version. Check them out > https://sumo.com/

    Aizen

    Thanks, but that isn’t quite what I’m looking for. Sumo is all about getting subscribers, what I’m interested in doing is creating a button that shares the current page URL into an email.

    ihor developer

    Unfortunately this would require code customizations, currently only %value% and %label% tokens are available in the attribute format field.

    Aizen

    I would happily pay for this in code snippet form or whatever is easiest for you. Thanks

    ihor developer

    Thanks, you can help improve HivePress and speed up the development by donating any amount via PayPal. This code snippet adds %listing_url% token to the attribute display format:

    add_filter(
    	'hivepress/v1/models/listing/fields',
    	function( $fields, $listing ) {
    		foreach ( $fields as $name => $field ) {
    			if ( isset( $field['display_template'] ) && strpos( $field['display_template'], '%listing_url%' ) !== false ) {
    				$fields[ $name ]['display_template'] = str_replace( '%listing_url%', get_permalink( $listing->get_id() ), $field['display_template'] );
    			}
    		}
    
    		return $fields;
    	},
    	1000,
    	2
    );

    So it’s possible to use it in the “mailto” link, for example by setting it as the email content https://stackoverflow.com/questions/4782068/can-i-set-subject-content-of-email-using-mailto

    Aizen

    Thanks this is amazing, but when i attempt to add it to the functions.php it won’t let me save, it says “Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over http://FTP.”

    Any idea?

    ihor developer

    Usually this error message is displayed when the theme files are not writable, so the built in WordPress code editor can’t change them https://wordpress.org/support/topic/error-message-something-went-wrong-your-change-may-not-have-been-saved-pleas/

    Aizen

    I can save other changes to it, but when I place that code it doesn’t work.

    Aizen

    I added the code via Cpanel, but wordpress comments it out in the admin dash, i think it’s an issue with the code – must be some kind of protection built into this new version of wpd?

    ihor developer

    It means that it’s added as an output outside of the PHP scope, please make sure that you add it to functions.php file, this file should start with <?php opening tag and it shouldn’t have the closing ?> tag, anything added after this closing tag will be output as text.

    Aizen

    Yes the functions.php file is what i have used, perhaps comment is the wrong word – when I add the code from cpanel it doesn’t show inside WP-admin even after refreshing / reloading the file. like the added code is invisible.

    ihor developer

    I tested this code snippet locally and it works for sure, please check that you add it to the current (preferably child theme) theme functions.php file, hope this helps https://createandcode.com/add-code-snippets-to-wordpress/

    Aizen

    Amazing thanks it has started working now – think it was a cache issue with my host.

    unitehearts

    I was looking for a way to get the Listing URL – happy to have found it. Thanks @Ihor

    unitehearts

    @Ihor – is there a way by which the Listing URL link can go in Whatsapp in such a way – that it will show a preview – as is often seen with URLs – with an image – or a small write up

    ihor developer

    This is related to Whatsapp, you can check if it fetches the image and short description when you send URL via the chat.

    infoindustry

    Where should I add this code? To function.php of ListingHive theme?

    add_filter(
    ‘hivepress/v1/models/listing/fields’,
    function( $fields, $listing ) {
    foreach ( $fields as $name => $field ) {
    if ( isset( $field[‘display_template’] ) && strpos( $field[‘display_template’], ‘%listing_url%’ ) !== false ) {
    $fields[ $name ][‘display_template’] = str_replace( ‘%listing_url%’, get_permalink( $listing->get_id() ), $field[‘display_template’] );
    }
    }

    return $fields;
    },
    1000,
    2
    );

    infoindustry

    I dont understand how to implement it, please explain
    I added it into snippet but dont see it

    ihor developer

    Please don’t edit HivePress or ListingHive directly because any changes will be erased on the update. If you’re going to customize ListingHive a lot you can create a child theme https://wordpress.org/plugins/child-theme-generator/ and add custom snippets to the child theme functions.php file. If there will be only a few snippets you can just use this plugin https://wordpress.org/plugins/code-snippets/

Viewing 20 posts - 1 through 20 (of 20 total)

You must be logged in to reply to this topic.