Support » Theme: Storefront » head_hook by page ID

  • losrack

    (@carlos-jaramillo)


    Hi,

    I want to insert some hooks by page id’s …
    I am using this right now:

    if ( is_page('4') );
    function add_meta_keyword() {
    	echo '<meta name="keyword" content="content here" />';
    }
    add_action('wp_head', 'add_meta_keyword');

    The problem is that if ( is_page('4') ); is not working because it is being shown no matter what page ID I put there.

    I have used this also

    /* head hook keywords */
    add_action( 'wp_head','carlos_head_keyword' );  
    function carlos_head_keyword() { ?> 
        <meta name="keyword" content="content here" />
    <?php }

    But when trying to use if page ID, it doesn’t work either.

    How can I insert hooks by page ID?

    Thanks

    • This topic was modified 1 year, 6 months ago by  losrack.
    • This topic was modified 1 year, 6 months ago by  losrack. Reason: addition
    • This topic was modified 1 year, 6 months ago by  losrack. Reason: addition
    • This topic was modified 1 year, 6 months ago by  losrack.
Viewing 1 replies (of 1 total)
  • Mikey Arce

    (@mikeyarce)

    Automattic Happiness Engineer

    Hi @carlos-jaramillo,

    > I want to insert some hooks by page id’s …

    Good question! So, the issue is that those conditional formats won’t really work this way. Instead, what you need to do is write the function, and inside the function, add the conditional.

    For example (and I haven’t tested this code, this just an example):

    function add_meta_keyword() {
     
    if ( is_page( 4 ) ) {
        echo '<meta name="keyword" content="content here" />';
    } else {
        // Do something else
    }
    }
    add_action('wp_head', 'add_meta_keyword');

    Cheers,

Viewing 1 replies (of 1 total)
  • The topic ‘head_hook by page ID’ is closed to new replies.