• Resolved KD35

    (@kd35)


    add_filter('wpseo_title', 'my_seo');
    function my_seo($title) {
    	$title = str_replace('-', ' ', $title);
    	return $title;
    }

    I wrote that little code but I want it to affect ONLY attachment pages, I run a gallery site so a lot of my images have – which Id rather replace with blank space. But when I run this code, it changes for all pages on my site, I want this code to only activate on the attachment pages.

    I know I have to use an IF statement(right?) but I am, stuck there, please assist.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    See https://codex.wordpress.org/Conditional_Tags

    is_attachment()

    add_filter('wpseo_title', 'my_seo');
    function my_seo($title) {
    	if ( is_attachment() )  {
               $title = str_replace('-', ' ', $title);
            }
    	return $title;
    }
    Thread Starter KD35

    (@kd35)

    EXACTLY what I needed!! Thanks a lot for taking your time to help me out and for the link to the conditional tags. Your code worked flawlessly.

    Again, thanks for the reply, means a lot!

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

The topic ‘If page is attachment, THEN run this code’ is closed to new replies.