Hi!
Can you help me understand what [a custom filter] would mean?
Sure! Let’s focus on your example. By default, Nelio Content will replace the placeholder {permalink}
with http://greaterthanthesum.com/aldo1/
, right? In order to do this, our plugin asks WordPress “hey, what’s the URL of this post?”, and WordPress replies “it’s this one”. Well, what I’m proposing is a slightly modification in our plugin (a filter) so that, when the plugin asks for a URL, WordPress replies “it’s this short link”.
How would WordPress tell us a different URL? That’s where you com in. Basically, you’d use the filter we create to “tweak” the expected result:
add_filter( 'nelio_content_permalink', 'nc_use_googl_short_link', 2 );
function nc_use_googl_short_link( $permalink, $post_id ) {
$short = get_post_meta( $post_id, '_googl_url', true ); // This needs tweaking.
if ( ! empty( $short ) ) {
return $short;
}//end if
return $permalink;
}//end nc_use_googl_short_link()
You should add the previous snippet (well, one that works for you) in your theme’s functions.php
file (or, even better, create a custom plugin).
Now, if you take a closer look at the function nc_use_googl_short_link
, you’ll see how it works. The function tries to determine the short link of a given post (in this case, I assumed it’s stored in a custom meta named _googl_url
, but you should figure out how to retrieve that value from the plugin you’re using). If we find a short link, we return it. Otherwise, we use the regular permalink.
Once this function is set in place, all social message’s {permalink}
will be changed to https://goo.gl/EuAKyk
, instead of http://greaterthanthesum.com/aldo1/
.
So, would the filter solution work for you?