how to edit functions.php in a child theme

Nearly all functions in esplanade can be overwritten in a child theme. Take the esplanade_admin_header_style() function for instance. Just before that function is the following line of code if ( ! function_exists( ‘esplanade_admin_header_style’ ) ) : . The important part here is if ( ! function_exists()): This means that the function it calls can be … Read more

Sanitize slug title

If you a look at the source you’ll see it’s because the sanitize_title filter fires after remove_accents() is called by sanitize_title(). It does however, pass the raw title as the second argument so you can perform any substitutions on the raw title, apply remove_accents() and return it: function wpsesanitize_title_extra( $title, $raw_title, $context ) { $new_title … Read more

Print Post Parent Title

You can just add a check: if ( ! empty ( $post->post_parent ) ) { $parent_title = get_the_title($post->post_parent); echo “<h1>$parent_title</h1>”; } or use setup_postdata(): setup_postdata( $post->post_parent ); the_title( /* arguments here*/ ); wp_reset_postdata();

Create Logout Link WordPress Admin Menu

You can use the awesome WP_Admin_Bar & hook in with admin_bar_menu: /** * Add a “Log out” link directly to the admin bar. * * @link http://wordpress.stackexchange.com/q/141446/1685 * * @param WP_Admin_Bar $wp_admin_bar */ function wpse_141446_admin_bar_logout( $wp_admin_bar ) { if ( is_user_logged_in() ) { $wp_admin_bar->add_menu( array( ‘id’ => ‘my-log-out’, ‘parent’ => ‘top-secondary’, ‘title’ => __( ‘Log … Read more

Loading all files within a directory

Loading files from a directory – the historical way The glob() function has three possible return values: Array( filenames ) => success Array() empty => nothing found FALSE => Error So the correct check would be $files = glob( sprintf( ‘%s/postypes/*.php’, get_stylesheet_directory() ) ); if ( empty( $files ) { _e( ‘No PHP files found’, … Read more

How to hide, and not to remove the attributes metabox?

The get_hidden_meta_boxes function (source link) provides two filters that you can use to hide the meta box. (Pick just one of them.) The first is default_hidden_meta_boxes (source), adding the metabox to the $hidden array will hide the metabox by default, but the user can select the screen options tab and choose to enable it. The … Read more

Get all categories of custom post even not assigned

I know how to get all categories with get_categories I think you’ve missed some of the arguments in get_categories. By default, empty categories (categories without posts) are hidden ‘hide_empty’ => 1, To get categories without posts, simply set hide_empty to 0 ‘hide_empty’ => 0, Here is an example $categories = get_categories( ‘hide_empty=0’ );