WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make two plugins work together where one of them puts a tag around every title with a filter function. I want it to exclude posts of another plugin that have custom post_type (ai1ec_event). But I can't get the post type if the id is wrong.

add_filter('the_title', 'mealingua_title_filter', 10);
function mealingua_title_filter($title) {
   $post_id = get_the_ID();
   #some stuff
   if (is_front_page() OR is_single() OR is_page()) {
        return '<span class="mealingua_title_container_' . $post_id . ' mealingua_title_container">' . $title . '</span>';
    } else {
        return $title;

But the post_id is always wrong in some places. One is the nav_menu at the top. The other is the plugin that I want to fix. There the id is always the one of the last post from the site. I tried the following to alternatives without success:

global $post;
$post_id= $post->ID;
global $wp_query;
$post_id = $wp_query->post->ID;

How can I work around this? What can I do? I am willing to mess with the code of either plugin but although I know PHP I have no experience with wordpress plugin coding. Thanks for any help.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.