Tag Info

Hot answers tagged

37

the new user email is sent using wp_new_user_notification() function which is pluggable meaning that you can overwrite it: // Redefine user notification function if ( !function_exists('wp_new_user_notification') ) { function wp_new_user_notification( $user_id, $plaintext_pass = '' ) { $user = new WP_User($user_id); $user_login = ...


7

You can handle this using the option_default_post_format filter: add_filter( 'option_default_post_format', 'slimline_default_post_format' ); /** * Posts of post_type_1 will be asides by default, but all other post types * will be the default set on the Settings > Writing admin panel */ function slimline_default_post_format( $format ) { global ...


6

Maybe so? Refined version of my earlier solution. add_filter( 'wp_dropdown_pages', 'add_cpt_to_front_page_dropdown', 10, 1 ); /** * Adds CPTs to the list of available pages for a static front page. * * @param string $select Existing select list. * @return string */ function add_cpt_to_front_page_dropdown( $select ) { if ( FALSE === strpos( ...


6

Ok - so I solved this. Here is what appears to be the problem. Comments are disabled by default for custom-post-types. This happens even if you have them enabled in the overall settings To fix it, all I had to do was the following: In SETTINGS > DISCUSSION uncheck the "Allow people to post comments on new articles" setting. Click "Save Changes" Now go ...


4

This is a little late, but I had to figure out the other part of this question on my own and thought I would share. To create a default menu and place it into a theme location, you will need a pre-existing location in the theme, and you will need to ensure any pages you link in your menu are also created already. In your theme's function.php, register any ...


4

The action hook save_post is called on save, but i don't know if you can add metadata at this time. But it should be possible to create/update your meta data after the post was saved with the action hook updated_post_meta. EDIT To pre-select some meta fields (custom fields) on the post creation screen, you have to add these meta values first with an empty ...


4

Why not just create a front-page.php template file, that uses either a normal query/Loop, or (if a custom Theme option is set to display the CPT on the Front Page), outputs a custom query/Loop, based on the CPT? The issue there is that you would have to create a separate Theme option to control the Front Page output, while at the same time instructing users ...


4

Thanks to @toscho for the useful answer, but it felt a bit hackish to me, so I poked around a bit and figured out I could add a filter instead: function wpa18013_add_pages_to_dropdown( $pages, $r ){ if('page_on_front' == $r['name']){ $args = array( 'post_type' => 'stack' ); $stacks = get_posts($args); ...


4

You should be calling the menus by name, not description: <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?> <?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>


4

There is a filter named default_content. It does exactly what the name says. :) Example: add_filter( 'default_content', 't5_preset_editor_content', 10, 2 ); /** * Fills the default content for post type 'post' if it is not empty. * * @param string $content * @param object $post * @return string */ function t5_preset_editor_content( $content, $post ) ...


4

As a security measure, WordPress includes these index.php files to account for hosts that by default enable directory browsing. Including them makes sure that no one can see the list of files in that directory, which could let them know what plugins or versions you are running and thus give them some things to try to hack your site. As long as you don't ...


3

You can try something like this. This will check if a page has child pages and if it does then it will redirect the first page in array ordered by menu order. // get child pages $child_page = get_pages( "child_of=" . $post->ID . "&sort_column=menu_order" ); if ( $child_page ) { // get id of first child page $firstchild = $child_page[0]; ...


3

I've answered a similar Question. Basically: create a Dropin plugin at the root of wp-content named install.php inside install.php, create a new version of the pluggable function wp_install_defaults() remove all unwanted defaults and customize at will, like: update_option('template', 'your-theme'); update_option('stylesheet', 'your-theme'); ...


3

Use the second parameter $post and check $post->post_type alongside a switch, it's easier and nicer to work with than several if else if else, etc.. add_filter( 'default_content', 'my_editor_content', 10, 2 ); function my_editor_content( $content, $post ) { switch( $post->post_type ) { case 'sources': $content = 'your ...


3

This will do: <?php /* * This filter only works with images, for all kind of media check: media_send_to_editor * The priority is set to 20 and it takes 8 arguments */ add_filter('image_send_to_editor', 'wpse_53577_img_wrapper', 20, 8); // We are only working with the $html argument, but you can play with all of them function ...


3

One simple method is to filter post_thumbnail_html, to add in a default image link: <?php function wpse55748_filter_post_thumbnail_html( $html ) { // If there is no post thumbnail, // Return a default image if ( '' == $html ) { return '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" width="150px" ...


3

Impossible. WordPress requires a default category, that’s hard coded. If you need a taxonomy without default value – create a custom taxonomy.


3

One option would be to modify the global Default Post Format setting, via Dashboard -> Settings -> Writing. Note that this setting is global, so it would set the default for all post types that support Post Formats. If you have no need of post formats for blog Posts, you could simply enable post-format support only for your custom post type, by ...


2

I'm not sure if there's another way, but manipulating the global variable $submenu can make this work. The following is just a manual hack (I'm not aware of any hook) and may fail on non-standard submenus set ups. The regular Post post type has a unique address and the rest of types has another one, hence two foreachs. add_action( 'admin_menu', ...


2

The best hook I can find is wpmu_new_blog (line 1086, wp-includes/ms-functions.php, wpmu_create_blog()) - it passes 6 arguments like so; do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta ); $meta is an array of initial site options, not to be confused with the options generated by populate_options(). Programatically creating ...


2

Unless you have a memcached-type plugin installed, wp_cache_set will only store data for the duration of the current script. Call or add the widget again in the same instance & you'll see it utilise the cache. As for ob_get_flush(), taken from the manual: Flush the output buffer, return it as a string and turn off output buffering In other words, ...


2

The code below shows the "post-thumbnail" aka the featured image if the post has one, if not depending on the category, the default thumbnail is shown (with the comments, the code should be self-explanatory): <?php // If the post has a featured image defined use it if( has_post_thumbnail() ) { the_post_thumbnail(); // Default image for Technology ...


2

wp_link_pages() and paginate_links() work in different contexts: The first on a single paginated page, the latter on an archive. So is_archive() should be your criterion to decide which text you use, or better: which filter you use in apply_filters().


2

This is set during user registration. You can change the value per filter 'user_register'. Sample code, not tested: /* Plugin Name: First name plus last name as default display name. */ add_action( 'user_register', 'wpse_67444_first_last_display_name' ); function wpse_67444_first_last_display_name( $user_id ) { $data = get_userdata( $userid ); // ...


2

There is a very easy solution to your problem. Just add a capability to the particular role of this user, through the Wp_Role class. Wordpress has this feature of Submitting for Review active for authors and contributor by default, but, if you want to use pages, you have to give them the edit_pages capability, but not the publish_pages one, so that they can ...


2

This is the proper method to add custom fields support (you don't get the blank fields when edit posts) function set_default_meta($post_ID){ $current_field_value = get_post_meta($post_ID,'Sort Order',true); $default_meta = '100'; // value if ($current_field_value == '' && !wp_is_post_revision($post_ID)){ ...


1

On the Product Edit page for the variable product, click on the "Variations" tab. Once you setup variations for the Colour you can set a "Default selection" at the bottom: http://cld.wthms.co/7LIv This will be the default option selected when a customer visits the page (if it is in stock). Example: http://cld.wthms.co/YQFO


1

You can use has_nav_menu() to check to see if the location has one assigned to it. If it does, use wp_get_nav_menu_items() to duplicate the menu, then assign it to the location you register in your theme. Here's what I have in mind. It's off the top of my head and will need more code and testing, but hopefully it's a good start for you: function ...


1

default_content runs when a post is loaded into the editor, actually. You can check for categories when the post is saved, but you'd want the save_post hook, probably. You want to check the $_REQUEST global. add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { global $_REQUEST; if ...


1

I'm working on a Php build script using Phing that installs WP along with some defaults (themes/plugins and custom code), it's still a work in progress. https://github.com/wycks/WordPhing/ Inside build.xml you will see some php options like the following which are run during install: //remove Hello Dolly delete_plugins(array('hello.php')); ...



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