This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tagged: ,

Cannot get post ID

  • Creator
  • #19405


    I am attempting to disable the menu for certain pages and added the following code to my child themes functions.php

    function themeblvd_custom_menu_content() {
                //echo $requested_page;
                //Code for custom landing page menue will go here
    /* Remove all other actions and add in our custom function */
        function themeblvd_custom_menu() {
    		$id = get_the_ID();
    		if ($id == 16961) {		
    	        remove_all_actions( 'themeblvd_header_menu' ); // Remove all other actions
        	    add_action( 'themeblvd_header_menu', 'themeblvd_custom_menu_content' ); // Add our custom function
    /* Hook everything in after theme has been loaded */
    add_action( 'after_setup_theme', 'themeblvd_custom_menu' );

    For some reason the ID of the page is not available in function themeblvd_custom_menu() but is in function themeblvd_custom_menu_content(). I have verified this by echoing the id in both functions.

    I have spent hours trying to resolve and searched for answers without success.

    Any help appreciated.

Viewing 1 replies (of 1 total)
  • Author
  • #19406
    Jason Bobich

    Hey Mark,

    You’re hooking your themeblvd_custom_menu() function to “after_setup_theme” — This is before WordPress has setup anything to do with the current loop. So, at this point, calling get_the_ID() won’t get you any where, as it’s meant to be used within the loop. First I’d suggest not using get_the_ID(), and second, to hook your function to something later on after the global $post object has been setup, like “wp”.

    Try something like this:

    function my_custom_menu_content() {
    	// ...
    function my_custom_menu() {
    	if ( is_page(16961) ) {		
    		remove_all_actions( 'themeblvd_header_menu' ); // Remove all other actions
    		add_action( 'themeblvd_header_menu', 'my_custom_menu_content' ); // Add our custom function
    add_action( 'wp', 'my_custom_menu' );

Viewing 1 replies (of 1 total)
  • The forum ‘Swagger Responsive WordPress Theme’ is closed to new topics and replies.