• I’m running the syntax theme on my site. I have a function in my child theme’s functions.php file that modifies the post titles. The problem I have is that it also modifies the post navigation links (shown as titles) at the bottom of the post.

    I used doing_filter to check for one of the plugins so I can skip modifying it like so:

    if(doing_filter('cmtt_tooltip_content_add')){ return $title; }

    How do I check to see if my title function is operating on a navigation link so I can skip modifying it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Offhand I’m not sure. Can you make your function more specific so it targets a more specific element that doesn’t include the post navigation.

    Can you provide a link to your site?

    Thread Starter mgargiullo

    (@mgargiullo)

    What element are you targeting with your function? Can you target just .entry-header .entry-title ?

    Thread Starter mgargiullo

    (@mgargiullo)

    I can’t just touch the css unfortunately as the function that creates the 3 style post title assigns a style to each piece.

    Image of Post Title

    The title of the post is entered like so:
    Aegilops cylindrica|jointed goat-grass|Poaceae

    This function beaks it apart and reformats it.

    function change_post_title($title) {
    	if(doing_filter('cmtt_tooltip_content_add')){ return $title; }
    	$cpt_tmp_title=explode("|",$title);
    	if ( in_the_loop() ) {
                    return " <span class=\"mtitle-latinname\">".$cpt_tmp_title[0]." </span><span class=\"mtitle-commonname\">".$cpt_tmp_title[1]." </span><span class=\"mtitle-familyname\">".$cpt_tmp_title[2]."</span>";
            }
    }

    At the bottom of the page, the post navigation is also formatted like the title:

    Post Navigation

    I’d like to modify the post navigation titles. Obviously the post navigation uses titles as it gets formatted. I’m looking for the right IF statement to use to identify when we’re modifying the titles used in post navigation or specifically the post title shown at the top of the page.

    In the code above, I already have a check in the function so I don’t modify the glossary terms.

    Ideally it would look like this (pseudo code):

    function change_post_title($title) {
    	if(doing_filter('cmtt_tooltip_content_add')){ return $title; }
    	$cpt_tmp_title=explode("|",$title);
    	if ( in_the_loop() ) {
                    if(this is the main post title){
                            return " <span class=\"mtitle-latinname\">".$cpt_tmp_title[0]." </span><span class=\"mtitle-commonname\">".$cpt_tmp_title[1]." </span><span class=\"mtitle-familyname\">".$cpt_tmp_title[2]."</span>";
                    }else{
                             return " <span class=\"smmtitle-latinname\">".$cpt_tmp_title[0]." </span><span class=\"smmtitle-commonname\">".$cpt_tmp_title[1]." </span><span class=\"smmtitle-familyname\">".$cpt_tmp_title[2]."</span>";
                    }
            }
    }

    Ideally, I could assign a different class to the post navigation titles vs. the post title.

    Ah, gotcha – thanks for explaining in more detail what you’re doing.

    My colleague and I both looked at this and we couldn’t think of any other parameters to add to the in_the_loop() function or any other conditions to add to your current function so that it excludes the title in the post navigation.

    Another route to go would be directly modifying the_title() output instead, but I’m wondering if a simpler route would just be to override the CSS itself to return the post navigation to a simpler display.

    For example, you could try adding something like this to your child theme:

    .navigation-post .mtitle-latinname, .navigation-post .mtitle-commonname, .navigation-post .mtitle-familyname {
      color: #000;
      font-size: 16px;
      font-weight: normal;
    }

    Let me know if that would work for you.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘functions.php modify title function changes secondary menu’ is closed to new replies.