1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HOWTO: Add a dynamic link to the XenForo thread in a WordPress Post

This code means you will not need to modify the theme

  1. LPH
    The XenScripts PHP files allow a WordPress post to be placed in the XenForo forum with a link back to the WP post. However, getting a link into the WordPress theme requires adding code to the theme. The following addition to the plugin makes this no longer necessary.

    Step 1: Create a file named xf-thread-link.php

    Step 2: Add the following code to the file

    PHP:
    1.  
    2. <?php
    3. /**
    4. * Creates a link to the XenForo thread below the content in WordPress post
    5. */
    6.  
    7. add_filter('the_content', 'show_thread_id');
    8.  
    9. if ( !function_exists('show_thread_id') ) :
    10.  
    11. function show_thread_id($content) {
    12.    global $XF, $wpdb;
    13.      echo $content;
    14.      echo '<br /><a href=" ' .  $XF->createLink($link) . 'threads/' . $XF->getThreadIdForPost($post_id) . '">Our Community</a>' ;
    15.      echo '<hr>';
    16. }
    17.  
    18. endif;
    19.  
    Step 3: Upload the file to the plugin directory. I prefer the plugin/include directory. Make note so you can include the location into the xf_integration.php file.

    Step 4: Add the following code to the xf_integration.php file

    PHP:
    1.  
    2. require_once( 'include/xf-thread-link.php' );
    3.