Title: Adding custom function() not working
Last modified: June 25, 2021

---

# Adding custom function() not working

 *  [wapoxac](https://wordpress.org/support/users/wapoxac/)
 * (@wapoxac)
 * [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/)
 * Hi,
 * I am trying to add a “noindex, follow” to paginated pages, and tried adding the
   following function to functions.php, but the paginated pages still had “index,
   follow”.
 *     ```
       function is_paged() {
           <meta name="robots" content="noindex,follow" />
       }
       ```
   
 * How can I get this to work preferably without using a plug-in. My function may
   not be correct, as I’m not a PHP developer.
    -  This topic was modified 5 years ago by [wapoxac](https://wordpress.org/support/users/wapoxac/).

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

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/#post-14490701)
 * The issue here is having this custom function over-write the existing values 
   if a meta name robots index tag has already been inserted into the page.
    You
   would need to actually add a hook into native head function.
 * [https://developer.wordpress.org/reference/functions/is_paged/](https://developer.wordpress.org/reference/functions/is_paged/)
 * Try this in your child theme:
 *     ```
       add_action('wp_head', 'meta_fix', 1);
       function meta_fix() {
         if(is_paged()) { echo "<meta name='robots' content='noindex, follow'/>"; }
       }
       ```
   
 *  Thread Starter [wapoxac](https://wordpress.org/support/users/wapoxac/)
 * (@wapoxac)
 * [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/#post-14490953)
 * Thanks for sharing your expertise Corrinarusso. That worked great!
 * There probably wouldn’t be a way to remove the original robots meta tag on just
   the paginated pages? So it doesn’t look this this where the original is listed
   first and then the injected afterwards?
 *     ```
       <meta name='robots' content='index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' />
       <meta name='robots' content='noindex, follow'/>
       ```
   
 * For anyone else who might benefit from this solution and know as little as me
   about PHP. I wrapped the code above in a PHP tag and put it in the functions.
   php file in WordPress > Appearance > Theme Editor > functions.php.
 * So it looks like this:
 *     ```
       <?php 
       add_action('wp_head', 'meta_fix', 1);
       function meta_fix() {
         if(is_paged()) { echo "<meta name='robots' content='noindex, follow'/>"; }
       }
       ?>
       ```
   
 * Remember to use a child-theme.
    -  This reply was modified 5 years ago by [wapoxac](https://wordpress.org/support/users/wapoxac/).
    -  This reply was modified 5 years ago by [wapoxac](https://wordpress.org/support/users/wapoxac/).
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/#post-14491616)
 * For WordPress 5.7+, the following should do what you want:
 *     ```
       function no_robots_paged($robots) {
       	if (is_paged()) {
       		$robots['index'] = $robots['follow'] = false;
       		$robots['noindex'] = $robots['nofollow'] = true;
       	}
   
       	return $robots;
       }
       add_filter('wp_robots', 'no_robots_paged', 999);
       ```
   
 *  Thread Starter [wapoxac](https://wordpress.org/support/users/wapoxac/)
 * (@wapoxac)
 * [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/#post-14491621)
 * Please disregard wrapping it in the PHP tags above and instead follow corrinarusso’s
   suggestion above. I managed to get a “Cookies are blocked due to unexpected output”
   error when I attempted to log in to WordPress and had to edit the functions.php
   via FTP to get access again.

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

The topic ‘Adding custom function() not working’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [wapoxac](https://wordpress.org/support/users/wapoxac/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/adding-custom-function-not-working/#post-14491621)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
