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.
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
These are all valid ways to reference another of your posts on the same blog.
[post2post id="25"]
[post2post id="25"/]
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.
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.
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:
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' );
easy-post-to-post-links.zip
inside the plugins directory for your site (typically wp-content/plugins/
)Settings
-> Post2Post
admin options page. Optionally customize the settings.easy-post-to-post-links.zip
inside the plugins directory for your site (typically wp-content/plugins/
)Settings
-> Post2Post
admin options page. Optionally customize the settings.The “Enable legacy HTML comment-style tag support?” setting controls whether the older, HTML comment style notation (from before v2.0 of the plugin) should be recognized. The “Enable legacy pseudo-shortcode tag support?” setting controls whether the older pseudo-shortcode syntax (from before v3.0 of the plugin) should be recognized You should only enable a particular legacy mode if you’ve used versions of this plugin prior to v3.0 and still want those post-to-post links to work without updating them. If you started using the plugin at v3.0 or later, you do not need to enable legacy support. Unnecessarily enabling legacy tag support will have a negative impact on the performance of your site.
If no post on your blog matches the value you specified as either a post ID or post slug, then the post-to-post tag in question disappears from the view, having been replaced with an empty string.
Yes. See the Filters section for an example of code to change the shortcode name. If you are going to make this short of change, it is recommended that you do so before making use of the shortcode in your posts/pages (unless you search and replace all occurrences of the original shortcode in other posts). Out of the box, the plugin only supports a single name for the shortcode.
Highlights:
Details:
reset_options()
to reference instance variable $options
reset_options()
resets values saved in the databasereset_caches()
to clear caches and memoized data. Use it in reset_options()
and verify_config()
verify_options()
with logic extracted from verify_config()
for initializing default option attributesadd_option()
to add a new option to the plugin’s configurationget_option_names()
disable_update_check()
to check for HTTP and HTTPS for plugin update check API URLWP_TESTS_DIR
to /tmp/wordpress-tests-lib
in bootstrap rather than erroring out if not defined via environment variablec2c_plugin_version()
.help_tabs_content()
, contextual_help()
show_examples()
, mce_external_plugins()
, mce_buttons()
get_instance()
static method for returning/creating singleton instance__clone()
and __wakeup()
)activation()
and uninstall()
static