How to create function from code?

You need to pass it at least 2 parameters, or it won’t know what to look for: <?php function custom_pagination($cat_id, $catnum) { // Start of Pagination $total_childs_query = get_categories( array( ‘parent’ => $cat_id, ‘hide_empty’ => ‘0’ )); $total_terms = count( $total_childs_query ); $pages = ceil($total_terms/$catnum); $base_url = get_term_link( $cat_id, get_query_var( ‘taxonomy’ ) ); // if … Read more

Batch update menu_order attribute alphabetically

Hopefully this helps someone else Dont forget to change “your_post_parent_id_here” with the parent id of your choosing. global $wpdb; $wpdb->query( ‘SELECT @i:=-1’ ); $result = $wpdb->query( ” UPDATE wp_posts SET menu_order = ( @i:= @i+1 ) WHERE post_parent=”your_post_parent_id_here” ORDER BY post_title; ” );

How to add class in plugin only for network site?

How are you invoking ngob_sitelist_slug? I’m gonna guess that you are doing something like $my_class = new ngob_sitelist_slug;. Doing it this way would require that your class have a constructor. if it doesn’t, you’ll get an error. You could still call your class methods statically: $my_thing = ngob_sitelist_slug::my_method(); Though technically you should add the static … Read more

Redeclare theme’s function in a plugin

You can only declare a function once. My reccomendation is that you put the functions in the plugin, then use filters to override in the theme, e.g. In the plugins: function my_awesome_function() { return apply_filters( ‘my_awesome_function’, “plugin” ); } In your theme: add_filter( ‘my_awesome_function’, function( $value ) { return “theme”; } ); Now every call … Read more

How to add new embed handler not supported by oembed?

Pretty sure it’s the fact you’re trying to use the regex pattern in your sprintf call, when you should be using… well, a sprintf format: $embed = sprintf( ‘<iframe class=”openload-video” src=”https://openload.co/embed/%s” scrolling=”no” frameborder=”0″ width=”700″ height=”430″ allowfullscreen=”true” webkitallowfullscreen=”true” mozallowfullscreen=”true”>></iframe>’, esc_attr( $matches[1] ) ); Note that you’re not using www in your embed url: https://openload.co/f/onU1gT5mkJ8/A_date_with_Lazar_Angelov.mp4 as expected … Read more

Get Current User info using wp_localize_script, in functions.php

If you read about this action here. You will see that this hook provides access to two parameters, $user->user_login (string) and $user ( WP_User ). Using it like this you will see all the info you have access to: function add_to_login($user_login, $user) { echo “<pre>”.print_r($user, true).”</pre>”; } add_action(‘wp_login’, ‘add_to_login’, 10, 2); But after a little … Read more

How To Remove Duplicate Menu Locations

You register an array of four menus. If you reformat your code, you will see it. […] array( ‘primary-nav’, __( ‘Primary Menu’), ‘footer-nav’, __( ‘Footer Menu’) ); […] Adapt your code to an array with custom keys and you will be fine: […] array( ‘primary-nav’ => __( ‘Primary Menu’), ‘footer-nav’ => __( ‘Footer Menu’) ); … Read more

CSS for menu item added via functions.php

Normally, menu items are rendered as an <li> tag with an <a> tag inside. You could simply wrap $todaysdate in an anchor so that this item will be styled like the others: add_filter(‘wp_nav_menu_items’,’add_todaysdate_in_menu’, 10, 2); function add_todaysdate_in_menu( $items, $args ) { if( $args->theme_location == ‘header-menu’) { $todaysdate = date(‘l jS F Y’); $items .= ‘<li … Read more

How does this function get the id of the most recent post?

prepare_payment() is calling wp_get_recent_posts() which returns an array of post by default. Only one post is being returned in this case, due to the $numberposts parameter being set to 1. $recent_posts holds the array of posts returned by wp_get_recent_posts(). The following line is setting $thePostID to the ID of the first post in the $recent_posts … Read more