How to add pages to custom menus on the fly [duplicate]

I guess it doesn’t need anymore explanation: $mymenu = wp_get_nav_menu_object(‘Main Navigation Menu’); $menuID = (int) $mymenu->term_id; $myPage = get_page_by_title(‘About Us’); $itemData = array( ‘menu-item-object-id’ => $myPage->ID, ‘menu-item-parent-id’ => 0, ‘menu-item-position’ => 2, ‘menu-item-object’ => ‘page’, ‘menu-item-type’ => ‘post_type’, ‘menu-item-status’ => ‘publish’ ); wp_update_nav_menu_item($menuID, 0, $itemData);

Variable from a plugin into a theme

Your webhost has disabled register_globals in the php.ini, so you have to “register” your variables manually everytime you want to use it. For example: <?php global $xavi; echo $xavi; ?> Another approach is using the $GLOBALS array: <?php echo $GLOBALS[‘xavi’]; ?> But in my opinion, you should avoid using globals. Instead use a simple registry-class, … Read more

Hook to get image filename when it is uploaded

The handle_upload hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve: function process_images($results) { if( $results[‘type’] === ‘image/jpeg’ ) { // or /png or /tif / /whatever … Read more

how to include javascript file and css file in wordpress

WordPress already ships with jQuery. There is no need to include it in your theme. Javascript Let’s say your jquery.tabify.js file is located in /js/jquery.tabify.js in your theme. Include the following code in your functions.php file: function jquery_tabify() { wp_enqueue_script( ‘jquery-tabify’, get_template_directory_uri() . ‘/js/jquery.tabify.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘jquery_tabify’ ); This will … Read more

Plugin development: How many plugin and WordPress version combinations to support?

Usually a plugin developed in WordPress version will run fine on several newer versions. What you need to care about is ‘deprecated` features/apis in WordPress. Any API in WordPress is not removed overnight, rather it remains deprecated for several versions. You will get such a list here: http://codex.wordpress.org/Category:Deprecated_Functions When you develop a plugin, you can … Read more