Support » Fixing WordPress » title_tag causing array to string conversion error

  • EDIT: This seems to be an Advanced Custom Fields conflict. Is it possible to move this to that forum? See below.

    I’m getting an array to string conversion error that points to these lines in general-template.php

    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    $title .= ” $sep ” . sprintf( __( ‘Page %s’ ), max( $paged, $page ) );
    }

    The HTML output looks like this: “<b>Notice</b>: Array to string conversion in <b>…\wp-includes\general-template.php</b> on line <b>884</b>
    <title>Site Name | Site Description. | Page Array</title>

    This seems to only happen on the homepage and archive templates. Single posts, pages, 404s, etc. don’t get the error. Any idea what’s going on?

    On further investigation, the following ACF function is causing the conflict. If I remove this, no problems.

    if( function_exists(‘acf_add_options_page’) ) {

    $page = acf_add_options_page(array(
    ‘page_title’ => ’45th Parallel Settings’,
    ‘menu_title’ => ’45th Parallel Settings’,
    ‘menu_slug’ => ‘theme-settings’,
    ‘capability’ => ‘edit_posts’,
    ‘redirect’ => false
    ));

    }

    Apparently, it’s the $page variable conflicting with new WP title-tag.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Did you find a solution to this issue? I’m seeing the same thing.

    Josh

    (@jmccallweb)

    I just changed the $page variable to something more unique, e.g. $my_page. Fixed it for me.

    I never would have found that!!! Thanks so much.

    Thanks Josh, I was wasting time over this. I submitted a bug report to @elliotcondon on his bug report forum (ACF).

    Hi guys

    Thanks for the tag.
    It sounds like using the variable $page is causing issues. Please note this can’t be replicated 100% of the time, so there must be something else to this story which is causing some function.php files to modify a global var instead of a local one.

    A simple fix is to place your ACF code within an action or function to avoid namespace issues!

    Thank you @elliotcondon,
    The init action seemed to work, others didn’t, do you see any reason not to do it this way?

    if(is_admin()) {
    
      if( function_exists('acf_add_options_page') ) {
    
        function wake_acf_add_options_page(){
    
          $page = acf_add_options_page(array(
            'page_title'  => 'WAKE R├ęglages',
            'menu_title'  => 'WAKE',
            'menu_slug'   => 'wake-general-settings',
            'capability'  => 'edit_posts',
            'post_id' => 'wko',
          ));
        }
        add_action('init', 'wake_acf_add_options_page');
      }
    }

    try this instead

    // add option pages
    if( function_exists('acf_add_options_page') ) {
        acf_add_options_page('Options Page');
    }

    in your example your are using $page which may be the cause

    Its the PHP Variable of $page
    @anton Keller, try this:

    if(is_admin()) {
    
      if( function_exists('acf_add_options_page') ) {
    
        function wake_acf_add_options_page(){
    
          $acfpage = acf_add_options_page(array(
            'page_title'  => 'WAKE R├ęglages',
            'menu_title'  => 'WAKE',
            'menu_slug'   => 'wake-general-settings',
            'capability'  => 'edit_posts',
            'post_id' => 'wko',
          ));
        }
        add_action('init', 'wake_acf_add_options_page');
      }
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘title_tag causing array to string conversion error’ is closed to new replies.