Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    You can use the wpas_post_url filter to customize the URL sent via Publicize. You can read more about it here:
    https://vip.wordpress.com/documentation/customizing-publicize-sharing-behavior/#implement-your-own-url-shortening-service

    I hope this helps.

    Thread Starter happyphantom

    (@happyphantom)

    thanks. I suppose it is about the code
    $url = apply_filters( 'wpas_post_url', wp_get_shortlink( $post->ID, true ), $post->ID, $this->slug );
    I’ve created a ‘get_shortlink’ filter for the wp_get_shortlink, that returns a customized url. The filter is called by the plugin, but Publicize does not post the customized url to facebook, it still posts the single post url.
    What should I do?
    thanks, Helene

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Publicize to Facebook is a bit different, since Facebook uses multiple data sources to build its post previews:

    • Data sent by WordPress.com servers to the WordPress.com Facebook app
    • Open Graph Meta tags inserted into your posts by Jetpack or another Open Graph plugin

    It’s consequently going to be a bit more difficult to customize the URL. But if you use Jetpack’s Open Graph meta tags, you could create to define a custom URL there, like so:

    function fb_cpt_single_og( $tags ) {
        if ( is_singular('your-cpt') ) {
            // Remove the url meta tag added by Jetpack
            unset( $tags['og:url'] );
    
           // Get the URL you want to share instead
            $fb_cpt_single = XX;
            $tags['og:url'] = esc_url( $fb_cpt_single );
        }
        return $tags;
    }
    add_filter( 'jetpack_open_graph_tags', 'fb_cpt_single_og' );

    Of course you’ll need to replace xx by the function you created to build your customized URL.

    I hope this helps.

    Thread Starter happyphantom

    (@happyphantom)

    Thanks, I’ll give that a try.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Customize URL in Jetpack / publicize’ is closed to new replies.