• Hi,
    how can I disable or overwrite the title and description meta tags from a page template?
    I would like to use variables from a GET parameter for title and description w/ this special dynamic page.

    <?php wp_head(); ?>
    

    everything else should be preserved (css … etc)

Viewing 10 replies - 1 through 10 (of 10 total)
  • WordPress doesn’t add title and description meta tags to the header. You must have a plugin doing this. How to remove them depends on the plugin. You should contact the plugin developer to find out how.

    Caveat emptor: I’m not a developer — I only play one here in the forums ??

    Have you checked the documentation for what actions are trigged by the wp_head() function?

    For the title meta tag, there is (since v4.1):

    add_action( 'wp_head', '_wp_render_title_tag', 1);

    So you can remove or manipulate it at will.

    But there’s none for the description meta tag, so you’ll have explicitly add it yourself if you’re building your own theme.

    Thread Starter cluster666

    (@cluster666)

    sorry for missing details, I use the yoast seo plugin

    In that case I recommend asking at https://www.ads-software.com/support/plugin/wordpress-seo so the plugin’s developers and support community can help you with this.

    The API is fully documented here: https://yoast.com/wordpress/plugins/seo/api/

    FILTERS:

    wpseo_title (string): Allows changing the title being output.

    wpseo_metadesc (string): Allows changing the meta description. Returning false will disable the meta description.

    Thread Starter cluster666

    (@cluster666)

    thanks, I was able to remove the yoast meta tags but how do I disable the WP title meta tag in the header of a specific page – if ( is_page ( 5352 ) )

    
    add_action('wp_head', 'remove_one_wpseo_og', 1);
    function remove_one_wpseo_og() {
      if ( is_page ( 5352 ) ) {
        remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), 30 );
      }
        /* Use a second if statement here when needed */
    }
    
    add_filter( 'wpseo_title', 'remove_one_wpseo_title' );
    function remove_one_wpseo_title() {
      if ( is_single ( 5352 ) ) {
        return false;
      } 
        /* Use a second if statement here when needed */
    }
    
    Moderator bcworkz

    (@bcworkz)

    Is post ID 5352 a post or a page? Do not use is_single() for pages. is_page() is fine. It appears the ‘wpseo_title’ filter is expecting a string be returned, not boolean. Just return an empty string.

    Thread Starter cluster666

    (@cluster666)

    Thanks, I have now replaced is_single w/ is_page ??
    But I still can not remove the wp meta title:

    // remove title from single page
    add_action('wp_head', 'wp_render_title_tag', 1);
    function wp_render_title_tag() {
      if ( is_page ( 5352 ) ) {
        remove_action( 'wp_head', '_wp_render_title_tag', 1 );
      }
    }
    Moderator bcworkz

    (@bcworkz)

    You must remove actions using the exact parameters used to add. Was _wp_render_title_tag added with priority 1? If so, try adding your removal callback with priority 0. I think your removal is happening after the _wp_render_title_tag callback has already been called.

    The other thing to do is use an earlier hook for removal. Earlier than wp_head, but later than the hook used to add. You can use the same hook to remove that was used to add if you hook with a larger priority to ensure the adding happens before removal.

    Or go back to using ‘wpseo_title’ filter, do return ''; instead of return false;

    Thread Starter cluster666

    (@cluster666)

    thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘remove title & description from page template?’ is closed to new replies.