112

You can extend the get_the_archive_title filter which I've mentioned in this answer add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } ...


104

get_template_directory_uri() will always return the URI of the current parent theme. To get the child theme URI instead, you need to use get_stylesheet_directory_uri(). You can find these in the documentation, along with a list of other useful functions for getting various theme directory locations. If you prefer to use a constant, then TEMPLATEPATH is ...


51

If you look at the source code of get_the_archive_title(), you will see that there is a filter supplied, called get_the_archive_title, through which you can filter the output from the function. You can use the following to change the output on a category page add_filter( 'get_the_archive_title', function ( $title ) { if( is_category() ) { $...


42

As of WordPress 4.5 you can use: get_post_type_archive_link( 'post' ); This handles the logic of getting the correct URL regardless of whether posts show up on the homepage or in a specified page.


41

Specifically editing the code you provided in the original question: add_filter( 'nav_menu_link_attributes', 'wpse121123_contact_menu_atts', 10, 3 ); function wpse121123_contact_menu_atts( $atts, $item, $args ) { // The ID of the target menu item $menu_target = 123; // inspect $item if ($item->ID == $menu_target) { $atts['data-toggle'] = '...


40

Checking to see if built in WordPress functions exist before calling them is for backward compatibility which IMHO is not needed. So if you see if ( function_exists( 'register_nav_menus' ) ) the theme author is supporting versions earlier than 3.0. You still sometimes see if ( function_exists( 'dynamic_sidebar' ) ) Why? I couldn't tell you because ...


39

Well the second bit of code is technically the correct way to do it. However, at the end of the add_settings_field() you can pass arguements. Please view the WordPress Add_Settings_Field function reference. This will help you in getting the best understanding of how the add_settings_field() function really works. Now, with that said, you could use a '...


38

I would highly recommend Daniel's much simpler solution over the one currently selected as correct: $user = get_userdata( $user_id ); if ( $user === false ) { //user id does not exist } else { //user id exists }


37

You can create new schedule times via cron_schedules: function my_cron_schedules($schedules){ if(!isset($schedules["5min"])){ $schedules["5min"] = array( 'interval' => 5*60, 'display' => __('Once every 5 minutes')); } if(!isset($schedules["30min"])){ $schedules["30min"] = array( 'interval'...


36

Use function single_term_title()


35

The default response from admin-ajax.php is, die( '0' ); ...by adding your own wp_die() or exit() or die() after returning your desired content prevents the default response from admin-ajax.php being returned as well. It also generally means that your ajax call has succeeded. Ultimately, to answer your question, it's meant to work this way. What you ...


34

The accepted answer works to remove the Category: prefix from category archive titles, but not other taxonomy or post types. To exclude other prefixes, there are two options: Rebuild the title for all the variants used in the original get_the_archive_title() function: // Return an alternate title, without prefix, for every type used in the ...


34

WordPress 5.3 introduces a considerably simpler way to achieve this. By registering theme support for HTML 5 for script and style, the type="" attribute will be omitted: add_action( 'after_setup_theme', function() { add_theme_support( 'html5', [ 'script', 'style' ] ); } );


32

esc_html() escapes a string so that it is not parsed as HTML. Characters like < are converted to &lt;, for example. This will look the same to the reader, but it means that if the value being output is <script> then it won't be interpreted by the browser as an actual script tag. Use this function whenever the value being output should not ...


31

The error message shows that the class description_walker extends the Walker_Nav_Menu class and overrides the start_el() method, but the signature differs from the method definition in the parent class. As mentioned in comments, it would be best to contact the developer of your theme and ask for a corrected version of the theme. If the developer cannot be ...


30

The most comprehensive method is get_current_screen added in WordPress 3.1 $screen = get_current_screen(); returns WP_Screen Object ( [action] => [base] => post [id] => post [is_network] => [is_user] => [parent_base] => edit [parent_file] => edit.php [post_type] => post [taxonomy] => )


27

As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_setup_theme' ); }


26

using wp_die(); at the end of AJAX function fixed the issue for me. e.g add_action( 'wp_ajax_my_ajax_function', 'my_ajax_function' ); function my_ajax_function(){ echo json_encode($myvar); wp_die(); }


25

You can also use $post_id = $_GET['post']; Or you can use a hook (probably better). function id_WPSE_114111() { global $post; $id = $post->ID; // do something } add_action( 'admin_notices', 'id_WPSE_114111' ); You will need to add a conditional since this will run on all admin pages, I recommend using get_current_screen(); For example to ...


25

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...


22

user_new_form is the hook that can do the magic here. function custom_user_profile_fields($user){ ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="company">Company Name</label></th> <td> <input type="text"...


21

Simply use CSS p:empty { display: none; }


19

To get WordPress admin email simply do: $admin_email = get_option('admin_email');


19

For CPT title Without word: ‘Archive’: If you are building custom archive template for a CPT, and want to output just the title of the CPT with no extra word like “Archive” use following function instead: post_type_archive_title(); From developer.wordpress.org


19

Here is a working solution (tested as is) The HTML (could be part of page content) <input type="text" name="keyword" id="keyword" onkeyup="fetch()"></input> <div id="datafetch">Search results will appear here</div> The JavaScript ( goes to your theme's functions.php ) // add the ajax ...


19

I think the only thing missing here is that you need to move add_action('wp_ajax_nopriv_ajaxlogin','ajax_login'); outside ajax_login_init. That code registers your Ajax handler, but when you only run it on wp_enqueue_scripts, it's already too late and wp_ajax_nopriv_ hooks are already run. So, have you tried something like this: function ajax_login_init(){...


19

The hook you're looking for is specifically wp_head which could look something like this: function theme_xyz_header_metadata() { // Post object if needed // global $post; // Page conditional if needed // if( is_page() ){} ?> <meta name="abc" content="xyz" /> <?php } add_action( 'wp_head', 'theme_xyz_header_metadata' ...


18

It is quite normal practice for code to not be a part of public API. But much of WP code is ancient and procedural. There are no technical ways to make a private function. These are semantically private, that is WP doesn't want you to use them, but it cannot actually forbid you to. There is a long history of "private" WP APIs being actively used in ...


17

One interesting approach would be to list all hooks to a file in a sequence of execution. add_action( 'all', '_20161224_printer' ); function _20161224_printer( $r ){ $line = microtime(true)*10000 . ' ' . $r . "\n"; $fp = fopen( ABSPATH . 'hooks.txt', 'a+'); fwrite($fp, $line); fclose($fp); } And you will get the output like this: ...


17

Disable all plugins and switch to the default theme. It should be gone now. Then enable each addon step by step, until the problem comes back. You know the source now, let’s say a plugin. The plugin calls probably wp_enqueue_script too early. Find all occurrences of that function, then make sure they are bound to specific actions: wp_register_script() ...


Only top voted, non community-wiki answers of a minimum length are eligible