Documentation

All the information you need in one place

How can I use shortlinks on my social messages?

As you probably know, you can use the {permalink} tag when creating social messages in Nelio Content. This tag is then replaced by the actual link of your post. But you can obviously create the message using the link directly. That is, instead of writing this:

Look at my newest post {permalink}

You can write this:

Look at my newest post https://short.link/post

But there’s a problem with this solution: you need to manually create all the social messages…

SOLUTION

Our plugin defines the following filter: nelio_content_post_permalink, with two arguments: $permalink and $post_ID. This means that you can easily create a custom function to make sure your posts are shared using a short link instead of the long one.

Here’s (roughly) how you’d do it:

1. Add a custom field in your post named, for example, nc_short_url:

Custom field for defining the proper short link of the post.
Custom field for defining the proper short link of the post.

2. Create a custom function such as this:

function nc_use_custom_short_link( $permalink, $post_id ) {
  $short_link = get_post_meta( $post_id, 'nc_short_url', true );
  return empty( $short_link ) ? $permalink : $short_link;
}//end nc_use_custom_short_link()
add_filter( 'nelio_content_post_permalink', 'nc_use_custom_short_link', 10, 2 );Code language: PHP (php)

As you can see, it’s a pretty simple function connected to the filter we mentioned before: it basically retrieves the post meta we just added and, if there’s one available, it returns it. Otherwise, it uses the default permalink.

If you don’t know where to place this function, follow these instructions.