Post-to-Post Links Wordpress Plugin - Rating, Reviews, Demo & Download
Plugin Description
Easily create a link to another post using a shortcode to reference the post by id or slug; the link text is the post’s title, unless overridden.
When writing your posts, you can refer to other posts either by ID, like so:
[post2post id="20"]
or by the post slug/name, like so:
[post2post id="hello-world"]
When viewed on your site, the post-to-post link tag is replaced with a permalink to the post you’ve referenced. By default, the text of the link will be the referenced post’s title, resulting in something like:
"<a href="http://example.com/archives/2005/04/01/hello-world/" title="Hellow World!">Hello World!</a>"
You can optionally customize the link text by specifying a text=""
attribute and value to the post-to-post link tag:
Check out [post2post id="hello-world"]my first post[/post2post].
Which yields:
Check out "<a href="http://example.com/archives/2011/07/01/hello-world/" title="Hello World!">my first post</a>".
The plugin provides its own admin options page via Settings
-> Post2Post
in the WordPress admin. Here you can define text that you want to appear before and/or after each post-to-post substitution, and if you want to enable legacy tag support. The plugin’s admin page also provides some documentation.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Examples
These are all valid ways to reference another of your posts on the same blog.
[post2post id="25"]
[post2post id="25"/]
- `[post2post id=”the-best-post-ever”]
- `[post2post id=”the-best-post-ever”/]
Assuming all of the above were used to reference the same post, the replacement for the post-to-post shortcut would be:
"<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">The Best Post Ever!</a>"
For any of the above you can also optionally wrap the shortcode around text. If so defined, that text will be used as the link text as opposed to the referenced post’s title.
[post2post id="25"]this post[/post2post]
[post2post id="blog-anniversary"]Congratulate me![/post2post]
The first of which would produce:
"<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">this post</a>"
You can also optionally definte the text that appears before and after the generated links. By default these are quotes.
- `[post2post id=”25″ before=” ” after=”!”]
Yields:
<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">this post</a>!<h3>Legacy</h3>
The legacy syntaxes — which are disabled by default and not recommended for use unless you’ve used version of the plugin earlier than v3.0 — allow you to refer to other posts by ID using a pseudo-shortcode syntax or an HTML comment syntax, like so:
[post="20"] or `<!--post="20"-->`
or by the post slug/name, like so:
[post="hello-world"] or `<!--post="hello-world"-->.`
The HTML comment notation was the original syntax employed by earlier versions of this plugin (pre v2.0). While it is still supported, it is no longer the primary and recommended syntax. The pseudo-shortcode syntax was in use between v2.0 and v3.0 of the plugin.
NOTE: The HTML comment syntax notation does NOT play well with the visual (aka rich-text) editor in the WordPress admin.
Examples of old legacy syntax follow. Those that use the pseudo-shortcode syntax (i.e. [post=25]
) only work if you’ve checked “Enable legacy pseudo-shortcode tag support?”. Those that use HTML comment notation (i.e. <!-- post="XX" -->
) only work if you’ve checked “Enable legacy HTML comment-style tag support?”.
[post=25]
[post="25"]
[post = "25"]
[post='25']
[post = '25']
[post="the-best-post-ever"]
[post = "the-best-post-ever"]
[post='the-best-post-ever']
[post = 'the-best-post-ever']
<!--post=25-->
<!-- post = 25 -->
<!--post="25"-->
<!--post = "25" -->
<!-- post='25'-->
<!-- post = '25' -->
NOTE: Only activate the legacy mode(s) that apply to your use of older versions of the plugin. If you started using the plugin at v3.0 or later, you should not activate either legacy mode.
Filters
The plugin exposes one filter for hooking. Typically, customizations utilizing this hook would be put into your active theme’s functions.php file, or used by another plugin.
c2c_post2post_shortcode (filter)
The ‘c2c_post2post_shortcode’ hook allows you to define an alternative to the default shortcode tag. By default the shortcode tag name used is ‘post2post’. It is recommended you only utilize this filter before making use of the plugin’s shortcode in posts and pages. If you change the shortcode tag name, then any existing shortcodes using an older name will no longer work (unless you employ further coding efforts).
Arguments:
- $shortcode (string)
Example:
/**
* Use a shorter shortcode: i.e. [p2p id="32"]
*
* @param string $shortcode The default shortcode name.
* @return string The new shortcode name.
*/
function change_post2post_shortcde( $shortcode ) {
return 'p2p';
}
add_filter( 'c2c_post2post_shortcode', 'change_post2post_shortcde' );