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

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

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.