Tag Info

New answers tagged

0

You should take a look at the WordPress hierarchy page in the documentation. Here it's the relevant part: page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php http://codex.wordpress.org/Template_Hierarchy


2

WordPress has finally documented all its hooks. :D You can browse and search there.


0

I adapted from here: http://wordpress.stackexchange.com/a/158485/373 /* ----------------------------------------- * Put excerpt meta-box before editor * ----------------------------------------- */ function my_add_excerpt_meta_box( $post_type ) { if ( in_array( $post_type, array( 'post', 'page' ) ) ) { add_meta_box( ...


0

Just to add to Pippin's answer, in my case some content were also being shown in other parts of the single page, e.g. sidebar. Checking just is_single() also triggered the content modification in the other areas. Here's another check so that only the main content will have appended stuff: function yourprefix_add_to_content( $content ) { if( is_single() ...


2

Plugins load before themes. The earliest hooks available to plugins is plugins_loaded (or muplugins_loaded for mu-plugins), while themes run on after_setup_theme and later hooks. So you better just load the file [that contains the class] on a specific hook in your plugin. It probably is best to load it on a lower priority than the default 10. Below I use 5 ...


0

Plugins are loaded before functions.php. You should include the class in your plugin if possible. I have had scenarios where a class was part of the theme, but also needed in a plugin where you couldn't assume the class was included in the theme. In those cases, I simply included the class in both places and wrapped it in a "class exists" check. Like ...


0

function jb_post_excerpt_meta_box($post) { remove_meta_box( 'postexcerpt' , $post->post_type , 'normal' ); ?> <div class="postbox" style="margin-bottom: 0;"> <h3 class="hndle"><span>Excerpt</span></h3> <div class="inside"> <label class="screen-reader-text" ...


1

If you are using WordPress 4.0+ you can do this using the wp_editor_settings and the global $pagenow to determine if you are on the comments page. add_filter( 'wp_editor_settings', 'remove_editor_quicktags', 10, 2 ); function remove_editor_quicktags( $settings, $id ){ global $pagenow; if ( $id == 'content' && $pagenow === 'comment.php' ){ ...


2

After checking out the code, the best way to do this would be to use the wp_editor_settings filter in /wp-includes/class-wp-editor.php. When you call wp_editor() it internally makes a call to _WP_Editors::editor($content, $editor_id, $settings);. This function first passes the $settings array through parse_settings() which uses that filter. add_filter( ...


3

PHP has a function, get_included_files() that returns all the file have been includedduring a request. However, if you use that fucntion you obtain all the files required: WordPress core files, plugin files... You need a way to: filter out files that do not belong to theme and child theme (if any) include only files loaded after main template has been ...


0

function parent_theme_name_scripts() { wp_enqueue_script( 'lektor', get_template_directory_uri() . '/js/synteza.js', array(), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'parent_theme_name_scripts' ); Add to your parents themes functions file. However, if you're adding scripts to a parent theme, create a child theme and add the script to the ...


2

get_header, get_footer, and get_sidebar all have corresponding actions that pass the name as an argument, so you can hook those actions, test for their existence via locate_template and log the names. get_template_part has an action, but it's dynamic and includes the slug, so unless you know the slugs, those will be difficult to hook. what you can do is ...


0

Did you try this? function hook_header() { $example_position = get_theme_mod( 'logo_placement' ); if( $example_position != '' ) { switch ( $example_position ) { case 'left': // Do nothing. The theme already aligns the logo to the left break; case 'right': echo '<style ...


1

The accepted arguments value is used by WordPress as $length argument for array_slice when performing the action. It means that, yes, if you pass 0 no argument will be passed to your callback. However, you should care of that only if your function acts differently if an argument is passed or not. A function like the one in OP, is defined without any ...


1

One alternative is to modify the $_POST['user_login'] input value when submitting new registration form, that is before WP process the registration form. A good hook to achieve this is login_form_register that fires before processing and rendering registration form. login_init also works but need more work to make sure we are on register action. ...


0

You can alter user login via the pre_user_login filter. Note that this runs when the user is created or updated. function wpd_custom_user_login( $user_login ) { $user_login = 'the-auto-generated-name'; return $user_login; } add_filter( 'pre_user_login' , 'wpd_custom_user_login' );


5

I use a code which differs from yours a little bit. There is no need to get the current screen using the enter_title_here-filter because you have already a post-object: /** * Filter: Modifies the standard placeholder text * @param string $title * @param WP_Post $post * @return string */ function my_enter_title_here( $title, $post ) { if ( ...


-1

function change_default_title( $title ) { $screen = get_current_screen(); // you can copy/paste the following if statement for other post types if( 'POST_TYPE' == $screen->post_type ) { $title = 'Custom placeholder text here'; } return $title; } add_filter( 'enter_title_here', 'change_default_title' );


0

I got it. public function auth($user, $username='') { if ( !empty($username) ) { return new WP_Error( 'broke', __( "custom error" ) ); } else return $user; } It only returns error if username is submitted. A good base for my plugin. But I didn't know how to set priority so thank you for that.


0

The filter runs on every page load, but the first argument will be a WP_User object only on successful submission. It will be null if nothing was submitted, but most likely it will be a WP_Error object, which you can check for. If you want to know the specific error you have to look at the errors the object contains. The case where the form was not submitted ...


2

Thanks guys, I found a solution: It's as easy as adding the post_type_category element to the arguments object within register_post_type(): $args = array( 'label' => 'sausages', 'description' => 'Sausages', 'labels' => $labels, 'post_type_category' => 'food', 'supports' => ...


1

I am make some assumptions here on where you are needing this but you could use is_post_type_archive() to check for archive pages and is_singular() for individual single posts both take either an string or array of post types. $post_types_group_one = array('movies', 'apples', 'sausages' ); $post_types_group_two = array('movies', 'apples', 'sausages', ...


1

I'm assuming you're not using a plugin to register your post types and doing them yourself. WordPress doesn't have an easy way to group or categorize post types together like what you're asking for. What I would suggest is to use built in attributes in a custom way. For example, when registering your post type there is a field called description. I don't see ...


3

If you hook some functions to the before_sidebar action, they will be executed in your code. Your action is now probably without any function hooked, so it returns nothing. Example: <?php add_action( 'before_sidebar', function() { echo 'Try me!'; }); add_action( 'before_sidebar', function() { echo 'Yep. '; }, 1); // this should output "Yep. Try ...


0

function property_slideshow( $content ) { if ( is_singular( 'property' ) ) { $custom_content = do_shortcode( '[portfolio_slideshow]' ); $custom_content .= $content; } return $custom_content; } add_filter( 'the_content', 'property_slideshow' ); The is_singular conditional tag checks if a singular post is being displayed ...


2

You need to redeclare the variable in your end_time() and also you don't need the user to be logged in.. You can try the below answer. // LOAD TIME CHECKER function start_timer() { global $time_start; $time_start = microtime(true); } add_action('wp_head', 'start_timer', 1); function end_time() { //try redeclaring the var global ...


0

Don't know if there was any change during the time that passed from the original question but as of 4.0 (and probably before) you get the post as a parameter to the hook and all that is needed to do is to check the post type (if you wander what happens when creating a new post the answer is that wordpress generates a dummy post if the post type set to the ...



Top 50 recent answers are included