Add data-id attribute to child page links

Assuming that your html is outputted by a wordpress menu sitting in a sidebar, you have to extend the Walker_Nav_Menu Class which is used by menu template functions like wp_nav_menu. As stated in the reference of wp_nav_menu, you could modify its output like: class My_DataId_Walker_Nav_Menu extends Walker_Nav_Menu { // other code found in original Walker_Nav_Menu … Read more

What does -> mean in WordPress?

NO -> is not wordpress specific, it is object operator in php. When you want to call a method of an instance then you call the method with -> Class SomeClass{ function example(){ return ‘This is an example function’ } } $obj = new SomeClass(); $obj->example(); // we are calling example function with -> operator … Read more

load ajax using admin-ajax.php

The codex says here that The wp_ajax_ hook follows the format “wp_ajax_$youraction”, where $youraction is your AJAX request’s ‘action’ property. I suppose in your js file you should go for: data: { action: ‘lateral_fluid’, // the $action to run }

New walker for walker_nav_menu to change inside container data

Well, you wouldn’t need a walker for that, if it’s simply adding a data attribute or something like that you could just use the items_wrap parameter. View wp_nav_menu() in Resources: $items_wrap = ‘<div class=”top-nav” mine=”something”>’; $items_wrap .= ‘<ul id=”%1$s” mine=”something2″ class=”nav %2$s”>%3$s</ul>’; $items_wrap .= ‘</div>’; wp_nav_menu( array( ‘container’ => false, ‘echo’ => true, ‘before’ => … Read more

Displaying text if post was within 5 hours

human_time_difference() will not work here as it returns a string in a human readable form. However, we can use some of the logic used there to construct a workable function You can try the following: (Untested) function get_custom__time_diff() { global $post; // Get the current time $current_time = time(); // Get the post date $post_date … Read more

PHP: Showing currency sign if input is a number

Here you go: According to documentation of get_post_meta , It will return a single value if the third parameter is true. It should be false to return an array. <?php $price = get_post_meta(get_the_ID(),’si-price’); foreach ($price as $element) { if (is_numeric($element)) { echo ‘$’ . $element; } else { echo $element; } } ?>

Double jQuery loaded

You can enqueue all your scripts the same way as you enqueue jQuery. Register and enqueue all your Javascripts like this (in your load_jquery function) wp_register_script ( ‘yourscripthandle’, //string $handle: a string to identify this script get_bloginfo( ‘template_url’ ) . ‘/js/yourcustomjs.js’, //string $src: Path of your script file array (‘jquery’ ), // array $deps = … Read more

Code Executing Too Late?

Per comments, declare it global before using in both (or all) places: global $sitetype; if ( $_SERVER[“HTTP_HOST”] === “domain1.com” ) { $sitetype = one; } //etc and global $sitetype; if ( $sitetype == all ){ echo “site type 1”; } //etc