Wordpress plugin to add link only


(Marc) #1

I wanted to setup a couple of wordpress blogs to share a discourse environment, but still leave wordpress native commenting in place, so just add “continue discussion about this post at discourse.otherdoman.com” above (or below) the native comments, and have that running aon a couple of wordpress blogs.
Also, I can see bloggers forgetting to tick the post to discourse option, can that be set to enabled by default.
I have discourse working on stage sites fine as it looks like it’s intended, but can’t figure these two things out.


(Simon Cossar) #2

I’m assuming you are using the WP Discourse plugin.

You can publish a post from WordPress to Discourse without enabling Discourse comments for your post. Do this by not selecting ‘Use Discourse Comments’ on the WP Discourse Commenting setting page and then selecting ‘Publish post to Discourse’ on the WordPress edit page. This will publish your post to Discourse and allow you to have Discourse comments on the forum and WordPress comments on the website. When Discourse comments aren’t being used for WordPress posts, the plugin doesn’t add a ‘continue discussion’ link to the WordPress post. It wouldn’t be to hard to set it up to do that though.

You can set the ‘Auto Publish’ option on the plugin’s Publishing options tab. With this set, the ‘Publish post to Discourse’ checkbox will be pre-checked on the post edit page. It can be unchecked there if you have a post you don’t want to publish to Discourse.


(Marc) #3

Thank you @Simon_Cossar, confirms in both cases I am doing it right, so must be a bug in the plugin or wordpress that the check box is not staying ticked (I’ll debug further).
Would you know of a short code i could use to add the ‘continue discussion’ link so it took them to the right post in discourse?


(Simon Cossar) #4

I’m doing some work on the plugin in a couple of days. I’ll look at that as well.

There is this: Wp-discourse-shortcodes plugin
I haven’t worked on the plugin for a while. There are some things in it that I want to change about how it deals with groups and messages. The discourse_link shortcode should work for you. You’ll need to set login to false if you’re not using SSO between your website and your forum. The plugin’s documentation is here: GitHub - scossar/wp-discourse-shortcodes: Extends the wp-discourse plugin by adding shortcodes that can be used to link to the Discourse forum.


(Marc) #5

@Simon checkbox issue resolved, was a caching proxy, refreshing the page shows unticket but really ticked, ticking again really ticks it.

Sorry i dont know what to make of the short codes, is there one that is simply comment_at_current_article?


(Simon Cossar) #6

There might be one that will work. Where do you want to put the link to the forum topic?


(Marc) #7

[quote=“Simon_Cossar, post:6, topic:54041”]
Where do you want to put the link to the forum topic?
[/quote] at the bottom of the content of each wordpress post, to the corresponding autopost at discourse, the idea is to have multiple wordpress sites autoposting to a single discourse (which currently works well) but give the commentators an option of where to comment.


(Simon Cossar) #8

Assuming you’re not using SSO, you could try adding something to your theme’s functions.php file that hooks into the WordPress the_content filter.

This works quite well with a theme based off the ‘Twenty Sixteen’ theme. You can change the link text in the function, and customize or remove the $discourse_link_instructions text.


// Your theme's functions.php file.

function your_site_prefix_discourse_link( $content ) {
    global $post;

    if ( is_single() && get_post_meta( $post->ID, 'publish_to_discourse', true ) ) {
        $discourse_permalink         = get_post_meta( $post->ID, 'discourse_permalink', true );
        $discourse_link_instructions = '<p>Leave a comment here, or join the discussion on our forum.</p>';

        return $content . '<div class="discourse-topic-link">' . $discourse_link_instructions . '<a href="' . esc_url( $discourse_permalink ) . '">Comment on our forum</a></div>';
    }

    return $content;
}

add_filter( 'the_content', 'your_site_prefix_discourse_link' );


/* style.css */

.discourse-topic-link {
    padding-top: 1.75em;
    border-top: 1px solid #d1d1d1;
    font-family: "Helvetica Neue", sans-serif;
}

.discourse-topic-link a {
    display: inline-block;
    color: #ffffff;
    background-color: #007acc;
    padding: 0.84375em 0.875em 0.78125em;;
    border: 0;
    border-radius: 2px;
    font-family: "Helvetica Neue", sans-serif;
    font-weight: 700;
    letter-spacing: 0.046875em;
    line-height: 1;
    padding: 0.84375em 0.875em 0.78125em;
    text-transform: uppercase;
}

.discourse-topic-link a:hover {
    background: #0091e3;
}


(Marc) #9

yes, that would be a total mess with multiple blogs

as for themes, well I think most of them are Genesis, mine is currently, but it was 2016 last week, but that is very much what I had in mind and enough to get started with, thanks so much.