• Resolved Etienne

    (@epipo)


    Hello,

    I was just wondering if it would be possible to filter the permalink for some pages. I am using the shortcode and I need the permalink to be different than the current page/post. I have noticed a scriptlesssocialsharing_get_permalink filter but I am not sure how to use it.

    I want to do something like this:

    $postID = (is_page(18712)) ? get_query_var( 'pid', 12752 ) : get_the_ID();
    $permalink = get_the_permalink( $postID );
    $attributes['permalink'] = $permalink;
    apply_filters('scriptlesssocialsharing_get_permalink', 'sep_filter_sharing_permalink');

    Could you help me?
    Thanks!

    • This topic was modified 8 years, 4 months ago by Etienne.
    • This topic was modified 8 years, 4 months ago by Etienne.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Robin Cornett

    (@littlerchicken)

    I believe this will work, but you’ll want to double/triple check it (it worked for me locally, at least). I’ve revised your code to this:

    
    add_filter( 'scriptlesssocialsharing_get_permalink', 'sep_filter_sharing_permalink', 20, 3 );
    /**
     * Modify the Scriptless Social Sharing permalink on page 18712.
     * @param $permalink
     * @param $button_name
     * @param $attributes
     *
     * @return false|string
     */
    function sep_filter_sharing_permalink( $permalink, $button_name, $attributes ) {
    	if ( ! is_page( 18712 ) ) {
    		return $permalink;
    	}
    	$post_id = get_query_var( 'pid', 12752 );
    
    	return get_the_permalink( $post_id );
    }
    

    That should only modify the link on page 18712 and otherwise return the standard permalink. The function does not account for what to do if the post ID 12752 does not exist, so you may need to adjust it more.

    Please practice safe coding, make sure you have your files backed up, etc. Hope this helps get you started.

    Thread Starter Etienne

    (@epipo)

    Works like a charm, thanks a lot :)!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Filter permalink’ is closed to new replies.