Peter J. Herrel edited this page Jan 30, 2015 · 7 revisions
Clone this wiki locally

What does the plugin do?

WP What Links Here implements "what links here" functionality in WordPress, like seen on e.g. Wikipedia.

How does it work?

Whenever a page or post is published or edited, it is added to a background queue. At regular intervals this queue is processed by a cron job, updating the relations between posts linking and linked to.

How do I display the list?

(a) Use the [wp_what_links_here] shortcode to display the list in your post content.

(b) Echo the list in a template file:

$wlh = do_shortcode( '[wp_what_links_here]' );
if( '' !== $wlh )
    echo '<h2>What links here</h2>';
    echo $wlh;

(c) Append the list to the post content using a filter, e.g.:

add_filter( 'the_content', 'my_wp_wlh_the_content', 10, 1 );
function my_wp_wlh_the_content( $content )
    $wlh = do_shortcode( '[wp_what_links_here]' );

    if( '' !== $wlh )
        return $content . $wlh;

    return $content;

(d) To get a list of IDs, use wp_what_links_here( get_the_ID() ).

Are custom post types supported?

Yes. By default, the plugin works with all public post types. WordPress' built-in public post types are: post, page, and attachment.

To whitelist a specific set of post types (e.g. only interlink pages and posts, but exclude the product post type), use the wp_wlh_post_types filter:

add_filter( 'wp_wlh_post_types', 'config_wp_wlh_post_types', 0, 1 );
function config_wp_wlh_post_types( $post_types )
    return array( 'post', 'some_post_type', 'another_post_type' );

How do I change the cron interval?

You can change the default interval of two hours by defining the WP_WLH_CRON_INTERVAL constant in the wp-config.php file of your WordPress installation. Use an integer value representing seconds, e.g.:

define( 'WP_WLH_CRON_INTERVAL', 1800 ); // every 30 minutes

To ensure the background queue does not grow too large, choose a value in correlation to the degree of editing activity on your site.

Tip: You can use the WP Crontrol plugin to run the cron job at any time.

Any hooks I can use?

action hooks

  • wp_wlh_loaded
  • wp_wlh_queue_add
  • wp_wlh_queue_remove
  • wp_wlh_do_cron

filter hooks

  • wp_wlh_post_types
  • wp_wlh_cron_schedules
  • wp_wlh_queue_add
  • wp_wlh_queue_remove
  • wp_wlh_check_link
  • wp_wlh_shortcode_query_args
  • wp_wlh_shortcode_output_open
  • wp_wlh_shortcode_output_item
  • wp_wlh_shortcode_output_close
  • wp_wlh_shortcode_output
  • wp_wlh_linking_here
  • wp_wlh_linking_to
  • wp_wlh_the_content
  • wp_wlh_get_links

Code Snippets

Order posts by name

To sort the posts by title, put the following in a custom plugin or in the functions.php file of your (child) theme:

add_filter( 'wp_wlh_shortcode_query_args', 'my_wp_wlh_shortcode_query_args', 10, 1 );
function my_wp_wlh_shortcode_query_args( $query_args )
    $query_args['order'] = 'ASC';
    $query_args['orderby'] = 'title';

    return $query_args;