Hi Sebastian! Thanks for the update! Thank’s to your Plugin I finished my blogs’s Google+ transformation. Take a look here: https://birgerh.de
Now every post from Google+ is shown with a title made of the G+ post first line. The Blog’s post is directly linked to the Google+ post. Here is how I did it. It’s pretty easy but needs core template changes:
A.) First line creates post title
Change the “set title for post” section of gplus-crosspost.php using this code:
// set title for post
if ($activity->title) {
$post_title = preg_match('/^(.*)\n/', $activity->title, $matches);
$post_title = $matches[0];
} else if ($att_title) {
$post_title = preg_match('/^(.*)\n/', $att_title, $matches);
$post_title = $matches[0];
} else {
$post_title = 'Google+ post: No title available…';
}
Thanks the length limiter build in by Sebastian, thee title works perfect now.
B. Link posts directly to Google+
This is a major change and you need to know some of template files like functions.php, archive.php, blog.php, etc. You have change at least three (3) files:
Be aware of changes! Always backup files of the original code!
Step 1: Edit gplus-crosspost.php – Add the “title_url” add_post_meta to the “create post and add some meta information” section below “set title for post”
// create post and add some meta information we might need later
$post_id = wp_insert_post($new_post);
if ($post_id) {
add_post_meta($post_id, 'g_crossposting_posturl', $activity->url, TRUE);
add_post_meta($post_id, 'title_url', $activity->url, TRUE);
add_post_meta($post_id, 'g_crossposting_postid', $activity->id, TRUE);
}
We use the “title_url” meta tag to safe the orginal Google+ post URL and use the URL.
Step 2: Edit your templates functions.php – Update the functions.php within your template folder with the following code:
/**************************************************/
/* print post permalink */
/**************************************************/
function print_post_permalink() {
global $post;
$thePostID = $post->ID;
$post_id = get_post($thePostID);
$perm = get_permalink($post_id);
$post_keys = array(); $post_val = array();
$post_keys = get_post_custom_keys($thePostID);
if (!empty($post_keys)) {
foreach ($post_keys as $pkey) {
if ($pkey=='title_url') {
$post_val = get_post_custom_values($pkey);
}
}
if (empty($post_val)) {
$link = $perm;
} else {
$link = $post_val[0];
}
} else {
$link = $perm;
}
echo $link;
}
This function switches the URL when the meta tag “title_url” is used in posts. Like the Google+ posts where we added the tag in step one (1). Thanks for this to AgentWP’s post where I took the original code from: https://www.agentwp.com/how-to-link-wordpress-post-title-to-an-external-url
Step 3: Edit archive.php and other – Search for “<?php the_permalink(); ?>” whithin your templates files. Change these using your new function:
<?php print_post_permalink(); ?>">
I had to change this in my templates home.php and archive.php – but this might be different for your template.
Update all files and reload your blog.
Create a post on Google+ and trigger the Google+ Crosspost Plugin’s manual check. Every post imported now is marked with the meta tag “title_url” from Step 1. Your template recognizes the post’s “title_url” tag and shows the original URL thanks to the function build in Step 2. Note: There is still a post saved to your blog. When your template is using “the_permalink” (instead of the “print_post_permalink” shown in Step 3) everything is still working, only showing the post created in your blog.
Birger