Get page name or page id

Hi,

I need to insert a page name (or page id) for a google analytics tracker (SEO recommandation).
I need it in file functions.php.
How it is possible?

thanks.

Hi there,

Thanks for writing in! You should be able to follow this method.

add_action('wp_head', 'my_custom_google_analytics');
function my_custom_google_analytics() {
  if ( is_page( 123 ) ) {
?>
    <!– Add Google Analytics Code here by replacing this line –>

<?php }
}

You can locate Page/Post IDs by following this guide (https://theme.co/apex/forum/t/setup-how-to-locate-post-ids/59).

Hope that helps.

Hi,

Thanks for your answer. But I rather need to a syntax like %id_page% or &ABC->get(pageID)

Is it possible ?

This may be what you’re looking for:

add_action('wp_head', 'my_custom_google_analytics');

function my_custom_google_analytics() {

  $id = get_the_ID();
  
}

Thanks, I see this trick.

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.