What I've got so far
I've finally got the functions.php
plugin to append a string to custom post titles of a certain post type with this function:
function append_album_review_to_title( $title ) {
global $post;
$text = 'Album Review: ';
if ( get_post_type( $post->ID ) == 'album_review' && in_the_loop() ){
return $text . $title;
}
else {
return $title;
}
}
if(function_exists('add_filter')) {
add_filter('the_title', 'append_album_review_to_title');
}
and though it does almost everything I need it to, it still doesn't append the string to titles as they are posted via auto-posting plugins.
The Problem
The plugin I am using is NextScripts: Social Networks Auto Poster and everywhere I can see the title, the desired string is appended but when this plugin auto-posts, the string is not appended.
The Question
How can I change my function to also apply to the titles as they are output by auto-posting plugins?
UPDATE 1
Why in_the_loop()
?
I use in_the_loop()
because if I don't, the string gets appended to seemingly every link on the page. I think this may happen because the post_type I am appending to is a custom type. I just tried removing it, and of course "Album Review: " was added to every single link on the page.
Will %FULLTITLE%
only work with manual <meta>
s?
I tried using %FULLTITLE%
without manual <meta>
tags as you described, but it doesn't seem to append the string. The reason why I bothered to try it this way is because YOAST plugin (as you said) not only already includes these tags, but because it already appends "Album Review: " to the title where necessary. So, when I inspect source, in the <head>
, the tags are like:
<meta property="og:title" content="Album Review: [the rest of title]">
Is YOAST's appending not enough, and I need to do the manual tags?
(Apologies for this form of communication; WordPress StackExchange still won't allow me to comment or upvote.)
if(function_exists('add_filter')) {}
. Also, you know thatin_the_loop()
only target posts in the main loop