Title: Can I insert php code into my menu??
Last modified: August 20, 2016

---

# Can I insert php code into my menu??

 *  [Erve1879](https://wordpress.org/support/users/erve1879/)
 * (@erve1879)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/)
 * I’m trying to find a way of adding a piece of php code into my menu.
 * I’m trying to use this code:
 * `<?php echo get_category_by_slug('news')->category_count; ?>`
 * to add a number-of-posts-in-category count to my menu. The idea is that the categories
   in my menu (eg. NEWS) will show the number of posts in that category ie “NEWS(
   76)”.
 * I’ve tried adding the above code into the custom menu navigation label, but it
   just displays the code in raw form in the menu.
 * Is there any way to achieve what I am trying to do???
 * Thanks very much!!

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

 *  [jjvasquez](https://wordpress.org/support/users/jjvasquez/)
 * (@jjvasquez)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2184718)
 * try, if you know the category id
 * $cats = get_categories(‘include=4′,’hide_empty=1’);
    echo “<h1> count is “.$cats[
   0]->count.”</h1>”;
 *  Thread Starter [Erve1879](https://wordpress.org/support/users/erve1879/)
 * (@erve1879)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2184742)
 * Thanks jjvasquez – where do I insert the category id?
 *  Thread Starter [Erve1879](https://wordpress.org/support/users/erve1879/)
 * (@erve1879)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2184743)
 * I’ve tried inserting the code into the menu (in the Navigation Label box), but
   it just shows the raw code in the menu…..
 *  Thread Starter [Erve1879](https://wordpress.org/support/users/erve1879/)
 * (@erve1879)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2185055)
 * Does anyone else have any ideas??
 *  Thread Starter [Erve1879](https://wordpress.org/support/users/erve1879/)
 * (@erve1879)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2185056)
 * I would really love some help!!

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

The topic ‘Can I insert php code into my menu??’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [count](https://wordpress.org/support/topic-tag/count/)
 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * 5 replies
 * 2 participants
 * Last reply from: [Erve1879](https://wordpress.org/support/users/erve1879/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/can-i-insert-php-code-into-my-menu/#post-2185056)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
