INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
How to default display name to first name and last and disable the profile field Hi I have been looking for a way to default display name to first name and last and disable the profile field for all users except admin. I have looked at plugins and fixes on here but have found nothing that works. I am using wordpress 3.9.2. I cannot find anywhere in the settings or codex to at least default to first name and last name.
I was unable to solve this myself but I finally found a plugin to achieve this, not sure how I missed it in the Wordpress plugin repository. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "admin" }
Where can i design and modify a new mail template for sending emails to users when commenting? the mail sent by Wordpress is ok but its template is very simple and has no style or even a header or footer! its message has no information about my blog or logo. where can i edit its message body and/or where can i style this template?
There are several plugins to accomplish this. Like < or <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, admin, email" }
Can't login through wp-login.php on fresh installation I have currently installed a fresh Wordpress on a dedicated server. It's the latest version with no plugins at all. Everything went successfully as always, I can see the website, but when I try to login through wp-login.php, no matter right or wrong data I'm inputting in the login form I receive "402 Payment Required" error! And a blank page, no reaction at all. I'm checking server logs and there is no any php error either. I want to note that wp-login.php is not corrupt and is working, change password functionality which is part of that page is fully working. Thanks!
We've installed mod_security php module and it had fixed the problem.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "login, wp login form" }
display taxonomy slug from term ID I'm trying to display the taxonomy slug from the term ID, thus my current code is like so: <?php $catinfo = get_category(array_pop(get_sub_field('sector_selector'))); ?> <?php print $catinfo->slug; ?> which isn't printing anything, a `var_dump($catinfo);` produces the following: array(1) { [0]=> int(59) } In theory `<?php print $catinfo->slug; ?>` should print the taxonomy slug, but it isn't? Any suggestions would be greatly appreciated!
You can use get_term_by() for this <?php $term_id = array_pop(get_sub_field('sector_selector')); $catinfo = get_term_by( 'id', $term_id, 'name_of_the_taxonomy' ); print $catinfo->slug;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom taxonomy, taxonomy, terms, categories" }
Is There a Difference Between Taxonomies and Categories? I've been reading the codex for WordPress closely and am confused about the vague definitions between what a Taxonomy is and what a Category is. For that matter, term is also a word that is used in the description of Taxonomies, but seems used in a manner that hints that it isn't solely limited to a Taxonomy. Both are described as a way to classify and group together posts. I do understand that Taxonomies are a more general form of categories, but how exactly do they relate to each other? Is there a subtle difference I'm just not picking up on?
Taxonomies, as previously described are a collective noun for the following * `category` * `post_tag` * `post_format` * `link_category` * custom taxonomy The first four are built-in taxonomies, while custom taxonomies are taxonomies that are manually created by the user with `register_taxonomy`. Custom Taxonomies can be hierarchical (like the build-in taxonomy `category`) or not (like post tags) The categories and tags that you create in the back end under the 'Posts' screen are in actual fact terms of the taxonomies `category` and `post_tag` You cannot create extra terms in `post_format`. `post_format` has built-in terms like `post_format_video`, `post_format_gallery` etc. See the codex for all post formats included ![enter image description here]( **EDIT** I have updated the Taxonomies page in the codex to include my diagram and the missing `post_format` taxonomy
stackexchange-wordpress
{ "answer_score": 68, "question_score": 54, "tags": "categories, taxonomy, tags, terms, post formats" }
Show attached media image if no thumbnail image detected I use the if ( has_post_thumbnail() ){} to check if the post have thumbnail image, but this echo get_attached_media('image', $post->ID); displays the word Array I need to show the attached image
If you want to use `get_attached_media()`, you can try for example: if( has_post_thumbnail() ) { the_post_thumbnail(); } else { $imgs = get_attached_media( 'image' ); if( count( $imgs ) > 0 ) { $img = array_shift( $imgs ); echo wp_get_attachment_image( $img->ID, 'thumbnail' ); } } to display one of the attached images, if there's no `featured` image available for the current post. Notice that you can't use `echo` to show the content of an _array_ , only for a _scalar_ variable.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "attachments, media, thumbnails" }
Why are passwords exportable as plain text in WordPress? On my WordPress 3.9.2 installation can I extract the users plain text passwords by going to Users, select all users, and choosing Bulk Actions Export. When I look in the mySQL database with phpMyAdmin, the passwords are hashed. **Question** How come all user passwords can be exported in plain text, and how can I prevent this? **Update** When I either export one user or "Export All Users" I get output similar to this User ID,Username,Payment Status,First Name,Last Name,Address,Zip,City,Country,Date,Sex,Phone no.,Email,Company,Password,TOS,Website,AIM,Yahoo IM,Jabber/Google Talk,Biographical Info,Registered,IP "31","xxx","paid","Jasmine","Lognnes","xxx","xxx","xxx","","xxx","female","","xxx","xxx","xxx","agree","","","","","","2012-01-26 18:13:19","xxx"
You cannot export passwords as plaintext in WordPress, because they are not stored in plaintext. What you see here is obviously the result of a very bad plugin. Fields like `Payment`, `Sex` or `Company` are not even part of the regular WordPress tables. For the future: Do not install plugins without prior tests and reviews in a safe environment. Use a local setup to find such security problems. Especially when you are dealing with other peoples data, this is a **requirement**. What you should do now: Disable all plugins until this export is not possible anymore. The last disabled plugin was probably the problem. Find all the tables that it has created, delete those tables. Uninstall that plugin.
stackexchange-wordpress
{ "answer_score": 15, "question_score": 8, "tags": "security, password" }
Theme Splash Image within the "Appearance -> Themes" control panel I have created a theme, and its all working fine. Within the WordPress control panel under **"Appearance -> Themes"** , you can see the available themes _(Twenty Fourteen, Twenty Thirteen etc etc)_ and they all have a splash image demonstrating what your blog could look like. My theme just shows a blank canvas. Is there a way of adding an image or something to represent my theme? I bet I have missed something really obvious. :/
In those themes there's a screenshot.png or screenshot.jpg that gets used. I would recommend using an 880x660px image ( for the aspect ratio, and for retina displays )
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, themes" }
How much resources are good enough for 3.9.2 I have the following specification: * memory_limit(maximal 128 MB), * max_execution_time(max 60 sec) * same PHP-Prozesse(max 10) Is this good enough for wordpress? I am having a small site with around 100 visits a day, so nothing really large. Do you think I could host 2 other wordpress installations on the server? I appreciate your answer!
Yes, that should be enough if you don’t install poorly written plugins or themes. You should use PHP 5.5 and its built-in OPcache and a multisite setup for more sites. This will reduce load time and the resources you need for the sites.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, server, hosting, server load" }
Dump custom post type database I have a custom post type filled with 7k entries by mistake. I want to empty the database for that custom post type. What is the best way to do it?
You can do that by two ways. One is by a function or other by SQL query. In your function just get all the posts having `post_type = <your-custom-post-type>` and delete those . Just add that function to theme `init` method. You can also do that through just SQL query. Query may be like below. `SELECT * FROM wp_posts WHERE post_type=<your-custom-post_type>` If your are non-technical then second options will be best for your. > **Note:** Before doing any thing just backup your database for your safety, if any thing goes wrong, you can directly replace the dump.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, database" }
Personalized message for each unique password-protected page How do I provide two different personalized messages for two different password-protected pages? I'm able to personalize the default message using the code below, but I'm not sure how to add a second unique message for visitors to a second password-protected page. I assume I would add some conditional code in my functions.php file but my attempts have failed. Any ideas? // to functions.php: change password message for protected page/s function change_pw_text($content) { $content = str_replace( 'This post is password protected. To view it please enter your password below:', 'Hint: Tell our system to show you, and it will.', $content); return $content; } add_filter('the_content','change_pw_text');
You should probably add in more checks, but this should get you started. function change_pw_text($content) { // Just to save processing other pages. if ( !is_page('page-slug-one') && !is_page('page-slug-two') ) return $content; $find = 'This post is password protected. To view it please enter your password below:'; if ( is_page('page-slug-one') ) $replace = 'Hint: Tell our system to show you, and it will.'; if ( is_page('page-slug-two') ) $replace = 'Sorry: This page requires you to be logged in.'; $content = str_replace( $find, $replace, $content ); return $content; } add_filter('the_content','change_pw_text'); For a nice resource on the possible Conditional Tags in WordPress see... <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "conditional content, password" }
How to open modal window when clicking a WP menu link? I'm making my first site with WP, I'm a Joomla Developper. I'm using wisten theme, and WP 3.9.2 I want to create a link in my the navigation that opens a modal window (not a new page) on click. Example - < , when you click the LOGIN link I have no clue of how I should do this in WordPress. The Jquery code for such an operation is not very difficult, the code is here : but I have no clue of how to integrate it. Any help would be appreciated
Using bootstrap's modal you could use this hook in your function.php file top do that: add_filter( 'nav_menu_link_attributes', 'menu_atts', 10, 3 ); function menu_atts( $atts, $item, $args ) { // The ID of the target menu item $menu_target = 24; // inspect $item if ($item->ID == $menu_target) { $atts['data-toggle'] = 'modal'; $atts['data-target'] = '#IDofModal'; } return $atts; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "menus" }
Show all sub categories? Is it possible to show all child/sub categories of all parent cats? I have the following hierarchy: Parent Cat/Tax \-- Sub 1 \-- Sub 2 Parent Cat/Tax 2 \-- Sub 1 \-- Sub 2 I would like to be able to show all the child categories on one template without the parent showing as well. Is that possible?
To exclude parent categories from your term list, you can just pass over them after you have retrieved your term list with `get_terms` Example: <?php $args = array( 'orderby' => 'name', ); $terms = get_terms( 'mytaxname', $args ); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ foreach ( $terms as $term ) { if( 0 == $term->parent ) continue; echo '<a href="' . get_category_link( $term ) . '">' . $term->name . '</a><br/>'; } } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories" }
How to call custom posts I have this custom post: add_action('init', 'eveniment_register'); function eveniment_register() { $args = array( 'label' => __('Evenimente'), 'singular_label' => __('Eveniment'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => true, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), 'taxonomies' => array('category','post_tag','post_thumbnail') ); register_post_type( 'eveniment' , $args ); } And all those custom-posts have a category with `ID=5.` In `category-5.php` I want to show all custom posts from that category. How I did it with normal posts with: while (have_posts()) : the_post(); doesn't work with custom posts. Any ideas? Thanks!
Don't change the main query. You can simply achieve what you want by using `pre_get_posts`.Fall back to the default loop in category-5.php and add the following to your functions.php function include_category_cpt( $query ) { if ( !is_admin() && $query->is_category( '5' ) && $query->is_main_query() ) { $query->set( 'post_type', 'eveniment' ); $query->set( 'post_status', 'publish' ); $query->set( 'posts_per_page', '-1' ); $query->set( 'ignore_sticky_posts', '1' ); } } add_action( 'pre_get_posts', 'include_category_cpt' ); Also, please note, `caller_get_posts` has long time been depreciated and as replaced with `posts_per_page` References * `is_category()` * When to use a custom query and when to use the main query
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types" }
How can I place a page link to the sidebar admin bar? Im trying to create a function that place my page link < in the Admin Sidebar, not in the top Admin Bar like the code bellow does know. function toolbar_link_to_my_page( $wp_admin_bar ) { $args = array( 'id' => 'my-page', 'title' => 'My Page', 'href' => ' 'meta' => array( 'class' => 'my-personal-page' ) ); $wp_admin_bar->add_node( $args ); } add_action( 'admin_bar_menu', 'toolbar_link_to_my_page', 999 ); Can anybody give me a hint on how to solve that...
I have added custom menu link by following. Hope it will be helpful. add_action( 'admin_menu' , 'custom_admin_menu_new_items' ); function custom_admin_menu_new_items() { global $menu; add_menu_page( 'My Page', 'My Page', 'manage_options', 'my-page', '','', 6 ); foreach($menu as $mIndex => $mData) { if($mData[2] == 'my-page') { $menu[$mIndex][2] = ' break; } } } Action hook `admin_menu` is used. New menu is added by `add_menu_page`. And after that URL of the menu is overridden by checking the slug in the foreach loop.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin menu, admin bar" }
2 wordpress site same database I have twoo websites on worpdress platform: * < * < On the server there are 2 different folders with same files, same config but one of them has: define('WP_HOME', ' define('WP_SITEURL', ' so is the same database but different url. I wanna made some changes on one of them, different logo, background so I need a second options table but the others to remain same for both websites. How can I have different logo, background and settings on the second website?
I would look into using HyperDB instead. This would allow you to pull data from several databases while one is replicated as the "master" database. < From the description page of the plugin: > It supports: > > * Read and write servers (replication) > * Configurable priority for reading and writing > * Local and remote datacenters > * Private and public networks **\- Different tables on different databases/hosts** > * Smart post-write master reads > * Failover for downed host > * Advanced statistics for profiling > Hope this helps you.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, custom post types, php, menus" }
Importing posts from old website to new conflicting post ID's? I am wondering when I am importing posts from my old site into my new website, which has already some posts in it. Do the imported posts get a new ID or do they overrule the existing posts ID's?
**_I can confirm that the imported post will get a new unique ID if (and only if) there already is an existing/conflicting ID in the target database._** Given a post to be imported with an ID of `7579` (represented in the WXR export file as `<wp:post_id>7579</wp:post_id>`) and an existing post with that exact same ID already in the target database, the generated ID for the imported post was `7583`. _(As far why`7583`? I would have thought auto increment but `7579` was an existing post, `7580` a revision of that post and `7581` a draft of some sort. So not exactly sure why `7582` was skipped.)_
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "database, import, id" }
jquery won't load in footer I wanted to move jquery to the site's footer, but that doesn't work. I've tried it with the following code. As you can see, I have a couple of another scripts and they load correctly on the footer. Only jquery won't work. //This adds our JavaScript Files function wel_adding_scripts() { wp_deregister_script('jquery'); wp_register_script('jquery', ' '', '2.1.1', true); wp_enqueue_script( 'jquery'); wp_register_script('jquery.mixitup', get_template_directory_uri() . 'js/jquery.mixitup.min.js','','1.1', true); wp_enqueue_script('jquery.mixitup'); wp_register_script('headroom', get_template_directory_uri() . 'js/headroom.min.js','','1.1', true); wp_enqueue_script('headroom'); } add_action( 'wp_enqueue_scripts', 'wel_adding_scripts' );
Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it's changed to be enqueued for footer. So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "functions, jquery, javascript, wp register script" }
Hide hour from displaying when using user_registered `$user->user_registered` displays "Registered since: 2014-08-18 07:25:22" I just want to show the date, not the hour. How can I hide the hour and just show the date? thank you
You could just show the first 10 characters of the string, like: echo substr($user->user_registered, 0, 10);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "users" }
Can't update multiple rows with $wpdb query it seems that I cannot update multiple rows to change the post_type of posts having a specific tag. I follow different method, even if it seems the good one is this one : global $wpdb; $result = $wpdb->query("UPDATE $wpdb->posts SET $wpdb->posts.post_type = 'editorial_post' WHERE $wpdb->posts.post_type = post AND $wpdb->postmeta.meta_key = 'tag' AND $wpdb->postmeta.meta_value = 'editorial'"); var_dump($result); `Var_dump()` always returns a null result. Can someone tell me where I'm wrong ? Thank you very much.
`$wpdb->query()` returns number of rows affected by the query. It's returning `NULL` indicates that there is an error in your query. The problem with your query is that you are updating `$wpdb->posts` table, but the condition depends on `$wpdb->postmeta` table. You have to join these tables for the query to work. Another problem is that you have to place the post inside quote $wpdb->posts.post_type = 'post' Try the following query global $wpdb; $result = $wpdb->query("UPDATE $wpdb->posts INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id SET $wpdb->posts.post_type = 'editorial_post' WHERE $wpdb->posts.post_type = 'post' AND $wpdb->postmeta.meta_key = 'tag' AND $wpdb->postmeta.meta_value = 'editorial'"); var_dump($result);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, query, wpdb" }
deregister scripts on certain page i need to exclude certain scripts from running on a certain page. i have tried this code but it's not working - when i inspect the page the scripts are still being loaded into the footer of my page. here is my code in functions.php add_action( 'wp_enqueue_scripts', 'my_deregister_javascript', 100 ); function my_deregister_javascript() { if ( !is_page('my-page') ) { wp_deregister_script( 'isotope' ); wp_deregister_script( 'anystretch' ); wp_deregister_script( 'imgliquid' ); wp_deregister_script( 'retina' ); wp_deregister_script( 'menutron' ); wp_deregister_script( 'imagesloaded' ); wp_deregister_script( 'myfunctions' ); } } what am i missing? thanks!
You have a basic mistake in your code. The following code if ( !is_page('my-page') ) { means that if you are **not** on that page, **deregister** the scripts. Have a look at the php operators > > ! -> Not !$x True if $x is not true > Also, why not exclude this specific page when you initially enqueue these scripts, something like add_action( 'wp_enqueue_scripts', 'my_register_javascript', 100 ); function my_register_javascript() { if ( !is_page('my-page') ) { // ENQUEUE/REGISTER SCRIPTS } } It is much cleaner and more efficient. I don't see the point in registerring a script and deregister it again. Rather register the scripts conditionally from the start
stackexchange-wordpress
{ "answer_score": 9, "question_score": 4, "tags": "functions, wp enqueue script, conditional tags" }
I want my wordpress loop to only display posts of the standard format I currently have the following php code for the content loop on my homepage. <?php if ( have_posts() ) : // Start the Loop. while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; twentyfourteen_paging_nav(); else : get_template_part( 'content', 'none' ); endif; ?> I want to know how I can specifically select one post format. I want the loop to only display posts of the standard post format.
Use `get_post_format()` inside your loop: if (have_posts()) : while (have_posts()) : the_post(); $format = get_post_format(); if (false === $format) { get_template_part('content', get_post_format()); } endwhile; twentyfourteen_paging_nav(); else : get_template_part('content', 'none'); endif;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, loop" }
Link to most recent child page in the header of a website I am trying to link to the most recent child page of a particular parent page. I can't seem to wrap my head around how to accomplish this. Does anyone have any input on this? Thank you very much in advance.
I found a solution! This is what I did: <?php query_posts(array('orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => 1, 'post_parent' => $page_id, 'post_type' => 'page')); while (have_posts()) { the_post(); ?> <a href="<?php the_permalink(); ?>">Link</a> <?php } ?> <?php wp_reset_query() ?> It makes a loop of sub-pages to a particular page and limits it to only 1 page. Nice and easy :) Hope this can be of any help to someone else.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, child pages" }
Wordpress Multisite: Adding actions to only one site I have Wordpress Multisite installed with WooCommerce network activated. I want to add an action to a hook in ONE of the sites that has WooCommerce installed, instead of all of them. For example, I only want this action that adds specific meta data to the order to occur on one of the sites with WooCommerce installed. add_action('woocommerce_checkout_update_order_meta', 'new_meta_values'), 2); function new_meta_values($order_id) { $order = new WC_Order($order_id); $items = $order->get_items(); foreach($items as $k => $v){ $item_id = $k; woocommerce_add_order_item_meta( $item_id, '_seminar_members_', $data); } } Is this possible?
Use `get_current_blog_id()` to check the current site. To run on site 2 only, use this: function new_meta_values($order_id) { if ( 2 !== get_current_blog_id() ) return; /* the rest of the function code */ }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 7, "tags": "multisite, hooks, actions, woocommerce offtopic" }
How to make "Blog pages show at most" setting not affect custom queries I want my blog page to display 5 posts at most. But I have many custom queries (wp_query) on my site, some of them embedded together: how to make `Settings > Reading > Blog pages show at most` setting NOT affect my custom queries?
If you're creating your own custom `WP_Query` queries, you can use the `posts_per_page` parameter: $args = array( // ... 'posts_per_page' => $some_number, //... ); $my_query = new WP_Query( $args ); If you want _all_ the posts, use `-1` as your `$some_number`. ### Reference * WP_Query » Pagination Parameters
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wp query" }
query to update post with featured images from array I have 100 existing posts of a custom post type that I need to update their featured images... How would I go about creating a query to randomly update these images from an array of say 20 images from the media library? Any pointers would be great, thanks!
This is pseudo-code answer. 1. First get the posts you want with `get_posts` (you can pass the post_type as an argument) 2. Then get the ID of the images you want to set as thumnbail 3. Now do a loop and try with a query similar to this one: "UPDATE wp_postmeta SET meta_value = $image_id WHERE post_id = $post_id AND meta_key = ''_thumbnail_id''" NOTE: To get the $image_id from the array of key you could use `array_rand`. You are gonna need `wpdb` to run the query. Read the docs, and ask a question if you have any doubts.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "post thumbnails" }
Changing wp_insert_post() location I know that `wp_insert_post()` insert posts into `wp_posts` table. I want to change that to insert posts into lets say `wp_posts2`. Can I do that? I need to do this because I don't want to mess data from 2 databases and I barely use them individually.
This is theoretically possible. While there is no explicit way to do this in post insert/update process, all queries go through `query` filter before being run on database. Practically this is a no go. The level of complexity in WP's handling of post querying is incomprehensible and full of edge cases. There is no easy telling how much would break over _seemingly_ simple tweak of having more than one posts table. There _are_ solutions and people doing this, but this is always driven by heavy operation requirements (elaborate content management needs, database sharding for performance and so on). In a nutshell as question posed — leave it alone before you mess up much more than you want to avoid there. :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp insert post" }
wp_nav_menu doesn't add current-menu-item when there is an url parameter `wp_nav_menu` doesn't add the `current-menu-item` CSS class when there is an url parameter in the url. Is there a way to ignore the url parameter?
I found the problem: I used a 'link' menu item instead of a 'page' menu item because it was originally a post type archive (but I changed that in a page). If I use a 'page' menu item the `current-menu-item` CSS class does work when there is an url parameter in the url.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "menus" }
Multiple 404.php templates based on a post_type Is it possible to have different 404 templates based on the post_type? So when `page` is not found `404.php` will be used, when `post` is not found `404-post.php` will be used. Or alternative, I would like just to display different message when blog post (`post_type=post`) is not found than when page is not found (`post_type=page`). Is there any hook I can use? Codex did not give me any usable hints on this.
It is possible but wordpress doesn't have any helpful constructs to help with that. The best approach is to modify your 404.php. Most of the information that you need should be in the main WP_query object and you should be able to do something like if (is_singular('post_tyoe_a')) { .... } else { .... } this is extremely untested and you might need to just try to see if enough information is included in the query to do what you want, but if not you can always just check if the URL matches the prefix used for the permalinks of your CPT.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "404 error" }
How to disable users changing their display_name? What would I have to do to prevent users changing their display_name?
You can use jQuery to disable the display name select. function disable_display_name() { global $pagenow; if ( $pagenow == 'profile.php' ) { ?> <script> jQuery( document ).ready(function() { jQuery('#display_name').prop('disabled', 'disabled'); }); </script> <?php } } add_action( 'admin_head', 'disable_display_name', 15 );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "users" }
Active menu item / category I was wondering if there's any way to discover which categories are "active" on a category archive page. This is for the purpose of menu highlighting. To demonstrate, compare these: (1) Parent category archive: < In the menu, the category is highlighted because it's active - cool. But so are both the dropdown menu links, its subcategories. (2) Post in the parent category: < Working perfectly. Only the parent category is active and highlighted, not the dropdowns. So it's really only (1) that's a problem, and I suspect it's not a CSS class issue because (2) works fine... So it that that archive page treats the subcategories as active? If so, can I disable that? Or what? Thanks!
Alas, this _is_ a CSS issue, caused by some difference in WP's classes applied. :) First you are misinterpreting your "test" case 2: 1. Dropdown isn't highlighted because (despite what post body says) it's not actually assigned the subcategory. 2. The styling applied is from `.current-menu-parent`, since post is obviously not a term in taxonomy. In your first case the class at work is `.current-menu-item`, since we _are_ looking at the term in taxonomy. Next the CSS rules `.current-menu-item a` applies to _all_ links inside of it and since dropdown HTML is inside top level item HTML it all gets styled as "current". You should be limiting such rules to _immediately nested_ links inside container — `.current-menu-item > a` (which is already done correctly for `.current-menu-parent > a`).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus, css" }
Sync Local site and Distant site I want to manage my WP site in local, then sync it to my git, and then automatically deploy it. In fact, I already have my site in production, and trying to make it work in local. The fact is I can make it work in local, but every link send me to the distant domain : mydomain.com instead of managing localhost. How should I manage it??? Tx
It sounds like you need to update the database to replace the guids and base URL. I recommend WP Migrate DB Pro to quickly sync two databases. Otherwise you need to run a few SQL statements to find and replace the old domain with the new domain. In PHPMyAdmin run the following statements from the SQL window. Replace old-domain with your exact distant domain, and the new-domain with your complete local address. UPDATE wp_options SET option_value = replace(option_value, ' ' WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, ' ' UPDATE wp_posts SET post_content = replace(post_content, ' ' Doing so will solve 90% of your link issues.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "localhost, git, github" }
wp.getPosts with status = 'trash' using node.js I was wondering how to set the filter option for wp.getPosts. I want to get posts with a status of 'trash'. filter is currently blank, and returns all posts other than trash. I am using the xmlrpc wordpress api and the node-wordpress plugin. < Here is my current code: wp.getPosts('<filter>', ['title','status'], function(err, data){ }); I am not sure what to put in the filter section, all the examples I could find are PHP examples and do not work in this context where I am using Javascript. Is it even possible to get the posts with a status of 'trash'?
I think you're looking for this... wp.getPosts({ status: 'trash', }, ['title','status'], function( err, data ) { console.log( data ); } });
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filters, trash, post status" }
Uploaded files have permission 000 two days ago i updated wp to the newest version and this problem occurs since then. when i upload files to the media library, their file permissions are set to 000. means no rights. the files are copied to the server, but since nobody has any right to read / write / execute i can't do anything with it (the files are defenetly on the server, but wp can not create the thumbnails etc. and i can't view the files with my ftp client, but when i download them, they are just fine). the uploads folder and all containing folders have 777 and i cant find any solution to this. is it some hosting problem, that just popped up?? thanks for the help
i deactivated all the plugins and reactivated them back again, just to find out than one of those was currupted / outdated. now everything works fine again.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permissions, uploads" }
Edit Image/Image Details - Replace button missing I have a strange problem. I am dynamically populating content into Wordpress' tinyMCE editor. Part of this content is a placeholder image, that the user can then replace. The issue is when I click the 'pencil' icon to edit, I am not given the "Replace" button like I would any other images. This is what I see: ![enter image description here]( This is what I expect, and works on images imported from the media library: ![enter image description here]( **Notice, the replace button is present in the second example. I guess because the image is hard-linked and wordpress has no way of knowing if the image exists in the media library. How can I dynamically import an image so this functionality is present?**
This has something to do with the HTML of a media object. I copy/pasted code from another image imported from the media gallery and it worked. Use this function to insert the content: < tinyMCE.activeEditor.setContent('<span>some</span> html');
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "php, jquery, uploads, media, media library" }
Stylesheet from wp_enqueue_style is overwritten by plugin I am using Font Awesome on my theme. wp_enqueue_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css'); I am using another plugin that uses Font Awesome, but its using an old version. wp_enqueue_style( 'fontawesome', '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css', array(), MSI_VERSION, 'all' ); The two methods are using the same handle so only one gets rendered in the HTML... and that is the plugin's old version. I could change my handle but then two Font Awesomes would be loading. I could hack the plugin, but, EWWW! How do I get my version of Font Awesome to take priority and load?
Just use `wp_register_style()` and `wp_enqueue_style()` correctly. **Register** your stylesheet on `wp_loaded`, **enqueue** it on `wp_enqueue_scripts`. add_action( 'wp_loaded', function() { wp_register_style( 'fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css' ); }); add_action( 'wp_enqueue_scripts', function() { wp_enqueue_style( 'fontawesome' ); }); When someone tries to call `wp_enqueue_style()` with an URL, WordPress will try to register it automatically, doing the work of `wp_register_style()` behind the curtains. But that will **fail** if the `$handle` is already registered. Always register scripts and stylesheet on `wp_loaded`. Never use `wp_enqueue_style()` and `wp_enqueue_script()` with the second parameter. Do not fiddle with priorities here. The conflicting plugin might change its own priority, and you start running behind again.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "wp enqueue style" }
How to configure folders with 'Child Theme'? I created a 'Child Theme' for customize my Template but I don't know how to subscribe some files that found in folders of the theme. I tried to do like this: Original files: theme/css/file.css I would like: child-theme/css/file.css Is it possible do that? Thanks in advance.
If you want to override existing parent's css file, create the exact same file with exact same path and it will override it. Example: _parentTheme/css/awesome_style.css_ To overwrite it you should create: _parentTheme-child/css/awesome_style.css_ More info: Child Themes -> Template Files You could also add rules to the existing css, you can read more about it in Template Hierarchy Or if you want to get stylesheet directory URI, you can use `get_stylesheet_directory_uri()`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "child theme, directory" }
Add custom objects/entities to Wordpress (I have some experience creating Wordpress themes but no experience in extending Wordpress functionality. I'm sure this must be a very common question, but I don't know how to search for the answer. All I could find is how to create custom menu items.) How can I create custom object types / entities in the database, like * Team members, i.e. an entry for each team member of the company * Reference projects, i.e. an entry for each project the company has done In the admin panel, it looks like this: !enter image description here For each object type, I want to define what properties they have (title, name, description, notes, image 1, image 2). **How can I do that? For what keywords should I search?**
I think what you want is to create what WorpPress calls "Custom Post Types". Please have a look at the Post Type page in the Codex that explains what Post Types are and how to create custom ones. Basically, here is the code to create the Object custom post type : add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'object', array( 'labels' => array( 'name' => __( 'Objects' ), 'singular_name' => __( 'Object' ) ), 'public' => true, 'has_archive' => true, ) ); } A side note : in your screenshot, the WordPress version seams very old (3.3 or something). Please Upgrade to the latest version to take advantage of the new features.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "custom field, customization" }
Change Wordpress URL in sql file via Terminal I've got a 40mb database file that I've exported from an old host and need to import it into a new host on a new domain. I normally open up the database in my code editor and find-replace, but as this file is so big, it's freezing my editor. Is there a way to do this via Terminal / the command line? I saw something about using `sed` when searching, but I can't get my head around how it works. Is there a simple command for doing this that exists already? I tried this but it doesn't work: sed 's/http:\/\/www.domain.com/http:\/\/www.newdomain.com/g' mydatabase.sql Thanks for any pointers. Osu
You should not use this technique to change the URL of your site : WordPress sometimes stores URLs in serialized strings. You find/replace will corrupt the serialized data and discard the whole content. You can use interconnect/it search and replace tool to change the domain without any risk. This tool even allow you to run a dry test to check what will be modified. If you prefer the `sed` technique, you should escape all special characters that have special meanings in regex like dots : sed 's| mydatabase.sql
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "database, migration, command line" }
I restricted wordpress by logged users. It's possible exclude a page? Here is my code for restrict my wordpress site: function restrict_access_if_logged_out(){ if (!is_user_logged_in() && !is_home()){ $redirect = home_url() . '/wp-login.php?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . urlencode($_SERVER["REQUEST_URI"])); wp_redirect( $redirect ); exit; } } add_action( 'wp', 'restrict_access_if_logged_out', 3 ); Now I want to add one exception for example for URL: example.com/home-page.
I wanted to restrict my website except a specific page. This is my solution: function restrict_access_if_logged_out(){ global $wp; if (!is_user_logged_in() && !is_home() && ($wp->query_vars['pagename'] != 'name-of-page') ){ $redirect = home_url() . '/wp-login.php?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . urlencode($_SERVER["REQUEST_URI"])); wp_redirect( $redirect ); exit; } } Only I added this: `&& ($wp->query_vars['pagename'] != 'name-of-page')` in IF clause and a global variable `$wp` for exclude a specific page. This method avoid redirect when the pages is 'name-of-page'. My inspiration here. And thanks @PieterGoosen for your solution in your post. :)
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "php, homepage, content restriction, logging" }
How to show subcategories using loop? i am using `wp_list_categories('child_of=54&title_li=')` method to display all the subcategories, but it is showing only one, how can i use it with loop to show all the subcategories properly.
I am giving solution of my own problem :) <?php $descendant= array('child_of'=>54); $categories = get_categories($descendant); foreach($categories as $category) : echo $category->name; endforeach; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wp query, loop, categories" }
Woocommerce product image when I upload in woocommerce image it uploads different sizes: 1. For category 2. Single 3. Thumb and keeps original file which is big... how can I auto delete this original file ?
You should be able to do this with the same filter that is talked about here. The full-size images are being kept by WordPress. It's not really a WooCommerce thing. As well as the settings for images in WooCommerce you will also need to set minimum image size in WordPress's `Settings>Media...` Then this script (see the link above for complete discussion) should remove the originals. add_filter( 'wp_generate_attachment_metadata', 'delete_fullsize_image' ); function delete_fullsize_image( $metadata ) { $upload_dir = wp_upload_dir(); $full_image_path = trailingslashit( $upload_dir['basedir'] ) . $metadata['file']; $deleted = unlink( $full_image_path ); return $metadata; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "woocommerce offtopic, images" }
Export Posts in excel How can i export post only with this data in excel :- Post title - Post URL - Author - publish Date Thanx
If you have direct access to your WordPress database, you could use a tool like PHPMyAdmin or HeidiSQL to query the _post_ and _user_ tables and extract the information you need from the appropriate tables. I discuss how an SQL query is constructed to get specific categories in Does WordPress Offer A Way to Get only Child Categories?. You can probably construct your own query to get the needed information with some time. Or, you could take the simple option and install something like Export 2 Excel.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -2, "tags": "excerpt" }
Sub Categories Keep Redirecting to Pages With Same Slugs What I want to do is have a `news` category with two sub categories (`property-registration` and `property-revitalization`). Going to /news works fine. However going to _/news/property-registration_ or _/news/property-revitalization_ redirects to same-named pages instead (`/programs/property-registration` and `/programs/property-revitalization` instead). I have downloaded a couple of plugins that let me save templates to categories but none of them worked and still got the same results. My permalink structure is `/%category%/%postname%/` for reference and no category base is set.
I figured out the problem. By adding `/.` at the end of the category base fixed the problem. So it is `news/.` instead of `news`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories, permalinks, redirect" }
Display site administrator's id by current blog id inside link I need to add current subsite admin id on the end of the ref link. For example 1.example.com site admin id is 4 - the link displayed on 1.example.com should look like < The working code (thx to @birgire): <?php function reflink_func( $atts ){ $uids = get_users( array( 'blog_id' => get_current_blog_id(), 'role' => 'administrator', 'fields' => 'ID', ) ); $url = add_query_arg( array( 'ref' => join( ',', $uids ) ), ' ); $link = '<a class="icallout-action btn btn-success btn-large" href="' . $url . '">Link text</a>'; return $link; } add_shortcode( 'reflink', 'reflink_func' ); ?>
If you want to construct for example: for multiple _administrators_ of the current sub site, you can try the following (untested): $uids = get_users( array( 'blog_id' => get_current_blog_id(), 'role' => 'administrator', 'fields' => 'ID', 'order_by' => 'ID', 'order' => 'ASC', ) ); echo $url = add_query_arg( array( 'ref' => join( ',', $uids ) ), ' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite, admin, id" }
Find sidebar.php in WP 3.9.2 I have tried to find sidebar.php in WP but I cant find it. Can anyone help me? I would like to remove achieve and META. I have been looking for this php file sidebar for a very long time now. Your sincerely
It's in your theme or setup as a sidebar on the Widgets page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sidebar" }
Rewrite Slug for CPT Archive Pages to Plural Name of Slug I have a custom post type with the rewritten slug of `plugin` creating the url structure of < Which makes the CPT Archive as < I'd like to rewrite it, without using a page and a custom page template, to use < (Which is the `labels=>Name` in the CPT). while keeping the slug for the single posts as `/plugin/` This would also need to support things like `/plugins/page/21 - which it currently does.
When you register the post type, set the argument `'has_archive'` to a string, in your case `plugins`. The doc block for `register_post_type()` says: > `@type bool|string $has_archive` > Whether there should be post type archives, or if a string, the archive slug to use. Will generate the proper rewrite rules if `$rewrite` is enabled. Default `false`. Minified example: register_post_type( 'plugin', [ 'has_archive' => 'plugins' ] );
stackexchange-wordpress
{ "answer_score": 21, "question_score": 11, "tags": "url rewriting" }
Text cut off after the character in TinyMCE I use the latest version of wordpress (v3.9.2, Taiwan Chinese Traditional), and found it can not display this Chinese word , but other Chinese words can be displayed normally. I just use this word on a post, and all the content after it is lost (became blank, this word disappeared too), after I saved the post to draft. What should I do?
This might be a limitation of JavaScript. is U+2A1C6 in Unicode, and codepoints above U+FFFF (which need four bytes) are coded via UTF-16 surrogates. And that … sucks. The canonical bug for that in WordPress is #13590 Inserting a 4-byte UTF-8 character truncates data. It was closed as _maybe later_ , because fixing it would require a change in the database encoding that WordPress’ current schema just cannot handle. You could try the plugin TinyMCE Chinese Convert and switch to Simplified Chinese to get around that.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "tinymce, visual editor, encoding" }
Make custom thumbnail size image in media_sideload_image function I am using customize `media_sideload_image` just as provided in this post by @G.M. Now I want to create different sizes of images other than which WP default uses. Please provide suggestion
You can do something like this in your functions file. add_image_size( 'category-thumb', 300 ); // 300 pixels wide (and unlimited height) add_image_size( 'homepage-thumb', 220, 180, true ); // (cropped) Then you can do something like this to give your custom size a certain name in the Admin area. add_filter( 'image_size_names_choose', 'my_custom_sizes' ); function my_custom_sizes( $sizes ) { return array_merge( $sizes, array( 'your-custom-size' => __( 'Your Custom Size Name' ), ) ); } More info can be found here and here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "uploads, media" }
Return link pages instead of displaying them Is there any WP function to return the pages links instead of displaying them with `wp_link_pages()`?
<?php $defaults = array( 'before' => '<p>' . __( 'Pages:' ), 'after' => '</p>', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'number', 'separator' => ' ', 'nextpagelink' => __( 'Next page' ), 'previouspagelink' => __( 'Previous page' ), 'pagelink' => '%', 'echo' => 0 ); ?> You have to set the `echo` parameter to `0`. Check the docs
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions" }
Force Network Activated Plugin to Run After Site Level Plugins I have a custom plugin I created and network activated it on WordPress Multi-Site install. I plan to use this plugin to override/enhance functionality for plugins available on my installation. The problem is, it looks like plugins at the network activation level run first, then the plugins that were activated on a site-by-site basis run their actions. I need my network activated plugin to run last so I can override actions and filters effectively. Looking at the plugin load order in the database for my main site doesn't even show my plugin so how can I make just my one custom plugin run last?
The order in which any plugins are loaded is not guaranteed and should not be relied upon. Instead, if you have processes which should happen after the plugins are loaded, then you should put those inside a function and then connect that function to the `plugins_loaded` action hook.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, multisite" }
How to edit blockquote image I'm using TinyMCE Advanced, to show more options to edit text. When I use the `blockquote`, an image appear, like this: !enter image description here How can I change this?
You can use `add_editor_style()` to override the default styles with your custom ones. Like this: function wpse158918_override_default_tinymce_styles() { add_editor_style( 'your-editor-styles.css' ); add_action( 'after_setup_theme', 'wpse158918_override_default_tinymce_styles' ); The code would go into your `functions.php`, the path to the stylesheet is relative to the directory of your current theme. If you are not doing this from your theme, but a plugin, then use the `mce_css` filter. Example from codex page: function plugin_mce_css( $mce_css ) { if ( ! empty( $mce_css ) ) $mce_css .= ','; $mce_css .= plugins_url( 'editor.css', __FILE__ ); return $mce_css; } add_filter( 'mce_css', 'plugin_mce_css' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tinymce" }
How to enqueue default scripts with dependency? I'm developing a plugin and for that I need jQuery and jQuery datepicker. I's taught that WordPress already enqueued some scripts, and I found 'jquery' and 'jquery-ui-datepicker' there. Where the datepicker is said to be dependent to jQuery. In that codex page it's also mentioned that, we can call a dependent script like the following: function my_scripts_method() { wp_enqueue_script( 'custom-script', plugins_url( '/js/custom_script.js' , __FILE__ ), array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); I got the point is right for any custom script. But what about the default scripts? **What to put on the source (`$src`) then?** wp_enqueue_script( 'jquery-ui-datepicker', $src, array( 'jquery' ) ); I can't put a null string (`''`) or a variable, anything, theoretically, and practically.
You don't have to provide source or dependencies, they're already registered by the script loader with those values, you just need to enqueue the proper handle.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "wp enqueue script, wp dependencies" }
How to upload/update theme from local - bitbucket - shared hosting? I am having tough time to figure out the best most appropriate way to maintain and update my custom theme for wordpress. I have setup local server (wamp) with wordrpess where I mainly develop my theme and push everything to bitbucket. At this point I usually just upload my theme from my local machine to ftp server theme folder - and voilà! However, this seems like an old approach. I see people talk more and more about dynamic update - push theme directly to host (from lets say bitbucket). I tried to search for best approach and a "how-to" tutorial however I failed. My hosting is shared and does have ssh access. How to use all of this - no idea. Maybe someone could direct me to a tutorial?
In a nutshell there are two basic approaches to this: 1. Build elsewhere and upload (in one way or another) result to the target server 2. Do everything right on target server There is variety of solutions that will do either of this or some mix of the two. The _simplest_ possible way for the conditions you had given (Bitbucket and server with Git) would be to: 1. Have Bitbucket make web hook call to your server. 2. Have server listen to the call and pull changes from specific deployable branch. Personally I had used myWebHook with success for this scheme. It implements Bitbucket support so it only takes uploading it to server and bit of configuration to have it going.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, git, shared hosting, hosting recommendation" }
How to use my style.css file outside of wordpress subdomain? I am building a wordpress theme from scratch on a subdomain and I want to use the same CSS files across my entire site. My problem is linking my wordpress PHP files (which are on the subdomain) to my CSS files (which are on the main domain). I have tried going into theme.php and changing the ['/style.css'] to an absolute reference such as '< but it doesn't work. function get_stylesheet_uri() { $stylesheet_dir_uri = get_stylesheet_directory_uri(); $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; I am assuming my subdomain doesn't have permissions to access my root folder or something is simply wrong with the syntax. I would like to link my wordpress theme to all my CSS files and frameworks and use theme site wide and on all my subdomains. Also, what would the solution be to link my Javascript files site-wide as well?
If you're using an absolute reference like that, you'd want to include the full file path, like < I believe any time you call the functions like get_stylesheet_directory() or get_stylesheet_directory_uri() it will return the path for the current theme. Just keep in mind that all themes need a style.css file. I would have posted this in a comment but I'm not allowed yet.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "php, theme development, css, subdomains" }
Move pagination numbers above plug-ins I'm having the following problem: ![]( I want to move the generated page numbers from `<!--nextpage-->` to appear below the post body, above the plugins (WordPress Related Posts, WP Author Box Lite & JetPack Share). Looking at `single.php`, `wp_link_pages()` comes right after `the_content()`. Are these plug-ins adding their content to `the_content()`? The documentation seems to give some alternative usage. Is this the only solution or is there a plug-in that will help with this problem? I'm using the BoldR Lite theme.
You can filter the content earlier than these plugins and add the navigation there. Remove `wp_link_pages()` from the template, and add the following code to the theme: add_filter( 'the_content', function( $content ) { return $content . wp_link_pages( array( 'echo' => FALSE ) ); }, -1 ); // Lower number = higher priority.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "pagination" }
How to remove version and thank you message from the admin footer I've used following codes and no luck **1** //Hide admin footer from admin function change_footer_admin () { return ' '; } add_filter('admin_footer_text', 'change_footer_admin', 9999); function change_footer_version() { return ' '; } add_filter( 'update_footer', 'change_footer_version', 9999); **2** function wpbeginner_remove_version() { return ''; } add_filter('the_generator', 'wpbeginner_remove_version'); **3** function my_footer_shh() { remove_filter( 'update_footer', 'core_update_footer' ); } add_action( 'admin_menu', 'my_footer_shh' ); Still I see those texts and version on my footer. !have a look at the screen shot So what is the accurate way to remove these? I've added these code snippets into my **child theme function.php**
This works for me: <?php /** Plugin Name: Admin Footer Text Remover **/ add_filter( 'admin_footer_text', '__return_empty_string', 11 ); add_filter( 'update_footer', '__return_empty_string', 11 ); where I use the `__return_empty_string` function as a callback.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 5, "tags": "footer" }
Deletion of shared options using uninstall.php I'm using `uninstall.php` for my plugin to delete all the traces my plugin did to a site on uninstall (delete). I did it in a good way, but even after the deletion there are some fields in the `options` table: * `uninstall_plugins` * `recently_activated` * `_site_transient_update_plugins` in these options there are multiple values from other plugins too. How can I take care of such traces, how can I remove all those traces too? I checked WooCommerce and found they leave no traces after there deletion, if the "delete data" checkbox is checked. How can I do so?
I don't think that you should touch these options. WordPress core already handles this, whether by removing the references to your plugin when it is deleted (as in `delete_plugins()`), or by being coded in such a way that it can ignore the reference to the removed plugin. Actually, none of these three options will last very long, since they are all regenerated regularly. The one is a transient, which naturally expires anyway. The plugins are removed from the recently activated list after a week. And the plugin is removed from the `uninstall_plugins` option by `uninstall_plugin()`. Also, WooCommerce doesn't touch these. It probably just looked like it removed itself because it was never added to these values in the first place, or was removed that quickly by WordPress. (It wouldn't have been added to `uninstall_plugins` at all, because it uses an `uninstall.php` file instead of a function). **So, TL;DR: You don't need to worry about this, WordPress will take care of it.**
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, options, uninstallation" }
How to use an array of categories as a dropdown? I need to use an array of existing categories as a dropdown option value then use the selected category ID. More exactly, I try to make a custom module to display the latest posts form selected category using Visual Composer plugin tutorial. I tried to use `wp_dropdown_categories` in the follwoing code but I get some errors and nothing works: array( 'param_name' => 'category_id', 'type' => 'dropdown', 'value' => wp_dropdown_categories, // here I'm stuck 'heading' => __('Category filter:', 'overmax'), 'description' => '', 'holder' => 'div', 'class' => '' ), Thanks
Try this, $categories_array = array(); $categories = get_categories(); foreach( $categories as $category ){ $categories_array[] = $category->term_id; } array( 'param_name' => 'category_id', 'type' => 'dropdown', 'value' => $categories_array, // here I'm stuck 'heading' => __('Category filter:', 'overmax'), 'description' => '', 'holder' => 'div', 'class' => '' ),
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "categories, array, dropdown" }
I need captcha implemtation for any custom form in wordpress need captcha implementation for any existing custom form in wordpress. I have already a form in my plugin where I need one captcha to be added. Please let me know the procedure to implement.
We can implement a security captcha image into our own plugin using Really Simple Captcha plugin. See the example explained in the following link, how to use the Really Simple Captcha Plugin with our own WordPress plugin Implementation of captcha image into your own plugin using Really Simple Captcha plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "captcha" }
Get "wp_get_nav_menu_items" to sort alphabetically I am trying to return a menu in alphabetical order and not the order set by the user in the backend. I have this code but it is not alphabetical: $args = array( 'order' => 'ASC', 'orderby' => 'title',); $menu= wp_get_nav_menu_items($menu->term_id, $args);
Absolutely no idea why I got a negative vote on this. Turns out this is actually a bug in wordpress: < The solution is to use "object" instead of "array". $args = array( 'orderby'=> 'title', 'output' => object); Hope it helps someone else.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sort" }
Repeatable WordPress custom fields in a metabox I would like to create a meta box where the user can add or remove a simple input field that holds an image url on posts.
I personally now use on _every_ project Advanced Custom Fields (< it is well-maintained, easy to manage, extremely powerful and ever-evolving in terms of features. It has a free and a Pro version (right now the plugin creator is moving towards a new version where there is only Pro, not single Add-Ons). Your repeater field would be in the Pro version. However, there seem to be other solutions plugin-based, like < which I though haven't tested, but it has a repeater field option as well and seems to be free.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, metabox" }
Setting the language of RSS feed What is the simplest / easiest way to set up the language of the rss feed. Currently, that field in my feed xml is blank, it looks like this <language></language> and i would like it to look like <language>en-US</language> Any help on how to easily implement it?
Within the default feed template you'll find something like this: <language><?php bloginfo_rss( 'language' ); ?></language> As you can see the bloginfo for the feed (`bloginfo_rss()`) is called (instead of `get_bloginfo()`). You can overwrite the feed language separately via a filter in your `functions.php`: add_filter('bloginfo_rss', 'custom_rss_lang_attr', 10, 2); function custom_rss_lang_attr($output, $show) { switch( $show ) { case 'language': $output = 'en-US'; break; } return $output; } **Update:** As @toscho pointed out it's bad practice to use a `switch` with just one case. Keep it simple and use an `if` statement: add_filter('bloginfo_rss', 'custom_rss_lang_attr', 10, 2); function custom_rss_lang_attr($output, $show) { if ( $show == 'language' ) { $output = 'en-US'; } return $output; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "rss, language" }
Restrict ability to edit pages by username I'm looking for a plugin or snippet with the following function: There is a WordPress Website with approx. 30 registered users. Every user get 2 Pages to edit his or her Products. Everyone can view the content but only the registered user can edit his oder her own Pages. Example: Peter can edit Page Id 222, Page 223 Tom can edit Page Id 224, 225 Admin can edit all All Pages will be shown to all unregistered Users Is there a PlugIn which allow this setting? The most Member Plugins I have seen, only allow to set roles and hide or view the content for other users. Thank you for your help! Cheers Marco
I striked for something a bit more complex, but similar in the core. The rather old-ish Role Scoper can do that, or you try the Premium version of its successor Press Permit. I befind both a bit complex if you only need a single usage option (manage page restrictions), but they work ;). Hope this helps!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
WordPress plugin DB upgrade I am writing plugin. I have added 1 custom table in database. Suppose my plugin's current version is 1.0 After few days i am upgrading plugin and now its version 1.2. Same for after some time and now version is 1.3 and ..... 1.4 Now for every release of plugin version I have made some changes in database. Than how can i upgrade database. I know about store db version in options table. But i don't know because some user update his plugin from 1.1 -> 1.2, other is from 1.1 -> 1.4......... some is 1.2 -> 1.4..etc.. Than there is only way to add all conditions to code or any other solution is available?????
In short, no. But it's not particularly complicated. Just add a new `version_compare` block each time you revise the database: $db_version = get_option( 'my_plugin_version' ); if ( version_compare( $db_version, '1.1', '<' ) ) { // Initial update code added in 1.1 } if ( version_compare( $db_version, '1.2', '<' ) ) { // Additional update code added in 1.2 } if ( version_compare( $db_version, '1.3', '<' ) ) { // And so forth } update_option( 'my_plugin_version', '1.3' ); This accounts for upgrades from any previous version, and only applies updates required to bring the db to the current version.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, database, upgrade" }
How to achieve post_status__not_in? How to fetch all posts with any status except trash and draft function pre_filter( $query ){ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $this->post_type ) { if ( !isset( $_GET['post_status'] ) ) { $query->set('post_status__not_in', array( 'trash', 'draft' ) ); } } }
Unfortunately there is no `post_status__not_in` query argument, but you can simply query for all statuses _other than_ trash & draft: $stati = array_keys( get_post_stati() ); unset( $stati['trash'], $stati['draft'] ); $stati = array_flip( $stati ); $query->set( 'post_status', $stati );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pre get posts" }
How do post IDs work in WordPress? So I have 2 blog posts so far and the first one has ID `8` and second one has ID `12`. How exactly does WordPress count those IDs? What if I want to change ID `8` and ID `12` to ID `1` and ID `2`? I have some knowledge about MySQL and I know that post IDs are related to the wp_posts table of the DataBase. How to edit the IDs? I have WordPress 3.9.2 and access to phpMyAdmin.
Don't change the Post ID. Wordpress uses serialized data, and id's have deep linking within the database.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, mysql, id" }
Should I set the html base url when using wordpress? In header.php I can do the following: <base href="<?php echo get_bloginfo('template_url');?>/"/> That way I can keep my layout images path relative. <img src="imgs/img.png"/> Instead of <img src="<?php echo get_bloginfo('template_url');?>"/> Is there any downside of settings the base url? Any possible conflicts with wordpress?
So in general there are two opinions on absolute versus relative URLs: * use relative URLs because easier to move around * use absolute URLs because easier to move around Confusing, yes. The argument boils down to that migrating things with relative URLs you don't need to change domain. The counter argument is that you might need to change _levels_ or URLs and then relative suddenly turns into complete nightmare. Regardless of which camp is "right" — WordPress is firmly in the absolute URL camp. All it's API functions will output absolute URLs and it's intended workflow for anything related in it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "urls" }
What's wrong with my $wpdb query? I'm just trying to query the first user, but it outputs this error, **WordPress database error** : [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''wp_users' WHERE ID = 1' at line 1] SELECT * FROM 'wp_users' WHERE ID = 1 And my code, <?php global $wpdb; $wpdb->show_errors(); $sql = $wpdb->prepare( "SELECT * FROM %s WHERE ID = %d" , $wpdb->users, 1); $results = $wpdb->get_results($sql); echo '<pre>'; print_r($results); echo '</pre>'; ?>
When you use `$wpdb->prepare` the placeholder `%s` is replaced with something between quotes, so, your query becomes: "SELECT * FROM 'wp_users' WHERE ID = 1" but table names in SQL queries must **not** be wrapped in quotes. So, the right way is: $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE ID = %d", 1 ); $results = $wpdb->get_results($sql); Note that this may not work because nothing assure that exists an user with the id = 1. (Actually someone discourages to have user with ID = 1 for security reason). If you want to pick first user is better to use something like: $user = $wpdb->get_row( "SELECT * FROM {$wpdb->users} ORDER BY ID ASC LIMIT 1" ); In this way you get first user row, no matter what its ID is.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database" }
Is it a good idea to init ajax functions only while 'DOING_AJAX' I wonder if it is a good solution to add (a lot) ajax `add_action()` only if `DOING_AJAX`is defined. Normally my setup is something like this: add_action('init', 'my_ajax_init'); function my_ajax_init(){ add_action('wp_ajax_mymail_method_1', 'my_ajax_method_1'); add_action('wp_ajax_mymail_method_2', 'my_ajax_method_2'); add_action('wp_ajax_mymail_method_3', 'my_ajax_method_3'); add_action('wp_ajax_mymail_method_4', 'my_ajax_method_4'); .... } I could prevent this actions on a "normal" page view with this: if(defined('DOING_AJAX') && DOING_AJAX){ add_action('init', 'my_ajax_init'); } Would this help in terms of performance?
The best way to know is to test yourself...but you will most likely find that the performance difference is negligible. Adding those actions don't mean that the "my_ajax_method_" will be evaluated. It is just setting up a reference...and the reference is only executed if the AJAX call comes in.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "ajax" }
Logo is not being displayed in header (Twentytwelve) So I have a image tag in the header.php of the Wordpress theme Twentytwelve like this: <header id="masthead" class="site-header" role="banner"> <hgroup> <img src="image/logokovil.png" alt="logo" height="100" width="100"> <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2> </hgroup> That's part of the code, the problem is that this logo is not being showed, instead I get a invalid image sign on the homepage. * The location of the image is: wp-content\themes\twentytwelve\image * The location of the header.php: wp-content\themes\twentytwelve So it looks correct to me, but it still doesn't show me the image? What can be wrong?
Replace the image code with the below one. Actually you are giving the root path in your image source but the image is in your theme folder. Also check if the images folder name is image or images. <img src="<?php bloginfo('template_directory'); ?>/image/logokovil.png" alt="logo" height="100" width="100">
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, headers, theme twenty twelve" }
Post__not_in only removing first 2 pages I am using post__not_in to remove pages from a query but it's ignoring anything more than 2 items My code: $selected_check = array(); $checks = new WP_Query( 'post_type=page&orderby=menu_order&order=ASC&posts_per_page=-1'); while($checks->have_posts()){ $checks->the_post(); global $post; $this_check = get_post_meta($post->ID, '_cmb_hide_home', true); if($this_check == 'on'){ $selected_check[] = $post->ID; } } wp_reset_postdata(); $new_check = implode(", ", $selected_check); $query1 = new WP_Query(array( 'post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => '-1', 'post__not_in' => array($new_check) )); My $new_checks array is currently 51, 76, 10, 21 but it's only working on the first 2 items Is there something I am missing in my code?
`post__not_in` should be an array of post IDs - remove the `implode` line and just pass `$selected_check` as the argument value instead of `array( $new_check )`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
How do we remove mystical [X] from text? Image included Wordpress has placed an uncalled for character on one of our page's text. We have a few hundred pages, and this only occurs on one. In the paragraph's text, between the words 'Music' and 'Students', WordPress has placed a [X] character. It is not in the visual or text views, and only appears on the actual page. It cannot be copied nor is there an extra space in the code. In essence there is no extra character between the two words, aside from the space. What caused this and how can it be removed? !X error in text If permissable, I can provide the URL containing the error.
I was able to resolve it by deleting the sentence and retyping it. The issue did not replicate. My best thought was that the import user imported text via Word.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "html, htmlspecialchars decode" }
Localized WordPress content for different sub-locales of same language? I have a site which serves Ireland & England. I want to move it to Wordpress. Currently all the content is the same when you visit the site & it runs off two urls, the Irish one: mysite.ie & the english mysite.co.uk I need to show different prices based on whether the user is visiting the Irish site or the English one. Currently I do something like: $host = $_SERVER['HTTP_HOST']; if($host == "www.mysite.ie") { //show Irish prices } I don't think I can run one WP installation off 2 domains for a start. It's not multilingual, so is there a way to show all the same content except for small differences based on the URL?
Well, actually, you _should_ view your site as requiring "multilingual" capabilities, even if the base language for both countries is identical, because the actual _locale_ for each is nevertheless different. More specifically, you can create variant "translations" for your British ('en_GB') and Irish ('en_IE') localizations. A plugin such WPML (WordPress Multilingual) can help you implement this, and it supports different URL schemes for differentiating between the localizations, including: * different domains (or subdomains) * different subdirectories
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "multisite, urls, localization, l10n" }
Best way to include wp-config.php I was wondering what way is the best to include wp-config.php into a plugin. I have read about relative paths that can fail if the plugin files are situated somewhere else.
The best way is to not do that. There's no need for a plugin file to ever include the wp-config.php. You're doing it backwards. WordPress loads plugins. Plugins don't load WordPress.
stackexchange-wordpress
{ "answer_score": 8, "question_score": -6, "tags": "plugins, wp config" }
An archive page without post format (just standard post) I'm trying to get posts with not marked with any type of post types (aside, audio etc). But I didn't find any solution to do this. I thought doing this with custom fields but site has a lot of posts...
I believe that you're asking about post **format** and not post **type**. Assuming that's correct, you'll probably be using `WP_Query` to query all posts of the post format "Standard." However, as noted in this trac ticket, there's strangely no way to query for the standard post format. Instead you need to query for all posts `NOT IN` any other format. Alex King put together a fairly involved snippet that does this. A simpler snippet is found in this Stackoverflow answer to a similar question: array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-quote','post-format-audio','post-format-gallery','post-format-image','post-format-link','post-format-video', 'post-format-aside'), 'operator' => 'NOT IN' ) The above would be the value of the `tax_query` argument in an instance of `WP_Query`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, loop, post formats" }
is_page() and is_page_template() not being differentiated I need to rearrange how my comments are displayed depending on the page template. My posts and standard pages are displayed in in the middle of the screen, and thus need to share the same comment layout. I then have a right sidebar page layout and so I need the comments pages with that template to be aligned to the left of the page. I am attempting to this like so <?php if( is_single() || is_page()): ?> <div class="col-lg-12"> <div class="row"> <div class="col-lg-8 col-lg-offset-2"> <?php else: ?> <?php if(is_page_template('right-sidebar.php')) ?> <div class="col-lg-12"> <div class="row"> <div class="col-lg-7 col-md-12"> <?php endif; ?> However, my single stadard pages are taking the layout of the `html` under the second if condition. What am I misunderstanding about this?
Your code will never get to the `is_page_template()` `if` statement because `is_page_template()` can only be true when `is_page()` is also true. It also looks like you've got some muddled `elseif` syntax (I think that's what you want?) and some generally inefficient code that repeats a lot. I'd do this: <?php if( is_page_template('right-sidebar.php') ) { // check for page template $layout_classes = 'col-lg-7 col-md-12'; } elseif( is_single() || is_page() ) { // it's not the page template. Is it at least a post or page? $layout_classes = 'col-lg-8 col-lg-offset-2'; } else { // I suspect you want a fallback condition, not sure what it is. $layout_classes = '{something}'; } ?> <div class="col-lg-12"> <div class="row"> <div class="<?php echo $layout_classes; ?>">
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, pages" }
Protect wp-login, but get an internal server error I am trying to protect my wp-login by #Protect wp-login <Files wp-login.php> AuthUserFile ~/.htpasswd AuthName "Private access" AuthType Basic require user myusername </Files> after the password protect I get a 500 internal server error and not the wp-admin How can I fix this? And how can I logout and try again to see if it works?? ps: source from the codex
You might have edited your .htaccess file in Windows notepad or text editor. If you did use Windows text editor then it must have added some special chars in .htaccess file and that will lead to 500 internal server error. Never edit in Windows text editor. Use notepad++ for editing .htaccess and .htpasswd files.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "htaccess" }
Make URL in custom field hyper link In my WordPress site I have created a custom field for author website link. but I don't know how to make it hyperlink, so people can click on it to surf that website. at this moment it only shows raw text. like: `"www.example.com"` my code is: <?php echo get_post_meta($post->ID, 'Author Website', true); ?>
Use this. get_post_meta($post->ID, 'custom-field-name', true); Where custom-field-name is the name of the custom field. You will have to add your custom field name in place of custom-field-name. Also to open link in new browser window/tab add `target="_blank"`. Always use `esc_url()` for URLs and `esc_html()` when you want to display a value without working HTML. $value = get_post_meta( $post->ID, 'Author Website', true ); if ( $value ) { // Returns an empty string for invalid URLs $url = esc_url( ' . $value ); if ( '' !== $url ) { $display = esc_html( $value ); print "<a href='$url' target='_blank'>$display</a>"; } } You should also store the protocol in the field, because some websites might not be available per `http`, just per `https`.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 1, "tags": "custom field" }
All links in my site start with localhost? This is my website ` The home page shows, but all links start with localhost/wordpress, rather than the current address, which is 173.214.165.83. The server is windows and runs IIS 7. Wordpress is in C:\inetpub\wwwroot\wordpress. Wordpress is installed by Web Platform Installer. I'm new to IIS. How should I fix the link problem? I hope I don't have to reinstall wordpress.
You should be able to configure the URL that WP uses for the links in the backend, at Settings->General.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "windows, iis" }
Meta query with string starting like pattern I have a custom WP_Query with the following meta_query: $meta_query = array(); $meta_query['relation'] = 'AND'; if(!empty($postcode)) { $meta_query[] = array( 'key' => 'postcode', 'value' => $postcode, 'compare' => 'LIKE' ); } if(!empty($email)) { $meta_query[] = array( 'key' => 'email_address', 'value' => $email, 'compare' => 'LIKE' ); } The problem with this is WordPress is wrapping each meta value in `%%` to use as part of the `LIKE` comparison in the query e.g `WHERE meta_value LIKE '%[email protected]%'` Is it possible to set up a meta_query so only one percentage sign is used, so we can check if a value starts with or ends with a phrase? e.g `WHERE meta_value LIKE 'hello@%'`
You could try the `REGEXP` version: 'meta_query' => array( array( 'key' => 'email_address', 'value' => '^hello@', 'compare' => 'REGEXP', ) ) where `^` matches the beginning of a string. You can check the MYSQL reference on `REGEXP` here for more info. Notice that these are the possible values of the meta `compare` parameter: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE','IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP', 'RLIKE' according to the WordPress 3.9.2 source. From the MYSQL ref: Name Description ------------------------------------------------------ NOT REGEXP Negation of REGEXP REGEXP Pattern matching using regular expressions RLIKE Synonym for REGEXP
stackexchange-wordpress
{ "answer_score": 19, "question_score": 9, "tags": "wp query, custom field, meta query" }
Check the Version of an Enqueue'd External Library I want to use an external font library in my plugin, but I want to do a version check first to determine if I should bother enqueue'ing my version or not. I know I can see if a library is already loaded -- `wp_script_is()` \-- but I don't know how to check the library's version. Any ideas? if ( wp_script_is() || wp_script_is( 'registered' ) ) { \\ version check here }
I can't find a nice way of doing it though wp_script_*, but you can go to the global directly: global $wp_scripts; $version = $wp_scripts->query( 'jquery' )->ver; Here the `query` returns the script's `_WP_Dependency` object, and then we can get the version from it. (Annoyingly `wp_script_is( ..., 'registered' )` fetches the `_WP_Dependency` but then casts the result to a bool to return.) This only works for registered scripts; apologies I don't know the distinction, but AFAICS a script can only be queued if it's registered, and it's only the registered data that holds the version.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "plugin development" }
Add date under slider/grid featured content I'd like to add post date under slider/grid text (which is category+Title) in my twenty fourteen wordpress child theme. Is it possible?
It is possible and quite easy to achieve. Here is how **STEP 1** Copy _content-featured-post.php_ to your child theme and open it up **STEP 2** Just after line 32, paste the following code <?php echo get_the_date( 'Y-m-d' ); ?> Save this change, and your done As you can see, `get_the_date` is used to return the post date > The get_the_date template tag retrieves the date the current $post was written. Unlike the_date() this tag will always return the date. To customize the date that is displayed, you can go and check out Formatting Date and Time
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization, theme twenty fourteen" }
How to disable autocomplete on the wp-login.php page It looks like there is not an easy way to add autocomplete="off" to the password input on the WordPress login page without editing the wp-login.php page directly. Is there something I'm missing? I do not want to modify core files.
Your only solution (without modifying core files) is to use JavaScript. function wpse_159462_login_form() { echo <<<html <script> document.getElementById( "user_pass" ).autocomplete = "off"; </script> html; } add_action( 'login_form', 'wpse_159462_login_form' ); Having said that, if you're not the only one that will be signing in I would advise against disabling autocomplete, it will almost certainly **** people off.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "login, autocomplete" }
Comments not enabled for custom post types I don't get this at all. I've looked online and I think I did everything I was supposed to, but my custom post type does not display a comments form. In functions.php. where I define the post type I have: `'supports' => array('title','editor','thumbnail', 'excerpt', 'comments'),` ( **note:** the 'comments' string wasn't there when the posts where made, I added it just now trying to fix this) In the `single-mytype.php` I added `<?php comments_template('comments.php'); ?>` to the loop. note: before I added the filename, I got nothing but now I get a "comments are closed" slug. If I edit the post, I see "enable comments" and "enable trackbacks" are unchecked, but if I check them they won't stay checked. If I check "enable comments" and add a comment to the admin form, that comment _will_ be displayed... but no form for other comments. What am I missing here?
Wordpress, by default don't enable comments on custom post types, and once you have added support for comments, you still get the following message: _Comments are closed_ You have to basically manually visit each custom post and enable comments in the post editor screen. There are however a workaround to enable comments by default in bulk. You can use the following snippet to enable comments in bulk function switch_on_comments_automatically(){ global $wpdb; $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open'")); // Switch comments on automatically }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, comments, comment form" }
Cannot add media to a page I am unable to add media to a page. I click the button on the page edit page and nothing happens. The web console of firefox says "TypeError: wp.Uploader is undefined". I already tried deactivating installed plug-ins and I set the default theme ("Twenty Fourteen"). I googled this problem and I only find people who are developing their own plug-ins who have this problem. :(
> Basically you need to open your “wp-config.php” file in the root of your WordPress Install. Search for this line: require_once(ABSPATH . 'wp-settings.php'); And just before it add this code: define('CONCATENATE_SCRIPTS', false); Now your WordPress Install should be fixed! Source: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages" }
Simple/basic use of get_current_screen I would like to load a stylesheet on only 3 admin pages: * post.php?post=7&action=edit * post.php?post=10&action=edit * post.php?post=18&action=edit I was trying with `admin_enqueue_script` but it doesn't seem to be capable of such specificity (see my related wpse post), which led me to `get_current_screen`. But all the examples and articles I find about `get_current_screen` refer to using it with a plugin and/or plugin options page: * < * < * < **I would simply like to use`get_current_screen` in my functions.php to determine if the admin page loaded is 1 of the 3 pages and if so load a css file.** A simple example would be very helpful (php novice here). Thank you for any help.
I haven't tested this but theoretically you could do something like this (Using the Codex as an Example): function load_custom_wp_admin_style() { $pageArr = array(1, 2, 3); if(isset($_GET['post']) && in_array($_GET['post'], $pageArr)){ wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' ); wp_enqueue_style( 'custom_wp_admin_css' ); } } add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' ); We get the current screen and set the page IDs we would like to include any scripts or styles. We then make sure that there is a `$_GET['post']` set which holds our post->ID and we also want to make sure we're in the correct post type (though you could probably skip the whole current screen thing entirely and just use `$_GET`). We then check to see if the current post ID is in our array of accepted IDs and if so: enqueue.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, css, admin css" }
How do I replace "Username" in the Wordpress login form? !enter image description here I would like to replace "Username" in the Wordpress login form with another word. How do I go about doing that?
You can use the `gettext` filter: /** * Rename the 'Username' label in wp-login.php * * @see */ add_filter( 'wp_login_errors', function( $errors ) { add_filter( 'gettext', 'wpse_change_username', 99, 3 ); return $errors; } ); function wpse_change_username( $translated_text, $untranslated_text, $domain ) { $old = "Username"; $new = "Jediname"; if ( $untranslated_text === $old ) $translated_text = $new; remove_filter( current_filter(), __FUNCTION__ ); return $translated_text; } where we hook into the `wp_login_errors`, which is very close to the `username` input. Here's a screenshot: !Username->Jediname
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "login, wp login form" }
WP_Query: Posts within category OR custom post type I don't like to bother you guys, but this is already driving me nuts. I have a legacy post model within a specific category called 'listas-2' that used shortcodes to show some fancy things. Now I have created a custom post type named 'lista' that does the same thing but way better, using post_metas. The issue now is that I have to make an archive of both at the same time with pagination, which contains the legacy and new posts. I can't manage to show both at the same time, already tried to add a tax_query but I can't because the custom post type doesn't use it, only the common post. I also tried to merge the queries but I got lots of pagination issues. The goal: A WP_Query that requests posts within the category 'listas-2' and custom posts named 'lista', that does not have categories. What can I do? Thanks in advance and sorry for my bad English, Vinicius
I really think that you have over complicated things here. Here is how I would treat the matter * First of all, create a custom post type (which you have already done) * Assign a custom taxonomy to it * Convert all the posts from the `listas-2` category to your created custom post type. See this post on how to * Re-assign your custom taxonomy to these converted posts
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, wp query" }
How to drag multiple menu items at once in WordPress? Say, I added 8 items to a menu. Now I want to bring all the 8 items under another item. Dragging them one by one can take ages. How do I drag them all at once?
Here's my solution : First, make all of your pages you want to move to be a subitem of some other item(the best way is creating one for this action bacuse you will delete parent item). !enter image description here !enter image description here Remeber that when you move your items you must move it with parent item like above. Then put items in place you choosen and delete parent item . Here - "Stowarzyszenie" . I hope that language won't be any problem :) All done! If you want to place moven items as a submenu then parent item must be on the level you choosen: !enter image description here
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "menus, sub menu" }
wp_update_user isn't instantly? I'm trying to update a user mail recieved by $_POST and use it instantly. It gets changed, however it outputs the old one. What is the way to do it? global $current_user; get_currentuserinfo(); if (isset($_POST['email'])) { wp_update_user( array('ID' => $current_user->ID, 'user_email' => $_POST['email']) ); get_currentuserinfo(); //just in case } echo '<p>You'll recieve a mail here: ' . $current_user->user_email . '</p>'; //outputs old mail Maybe it has to be with the global $current_user var? EDIT: Chuncky fix, global $current_user; get_currentuserinfo(); $email = $current_user->user_email; if (isset($_POST['email'])) { wp_update_user( array('ID' => $current_user->ID, 'user_email' => $_POST['email']) ); $email = $_POST['email']; } echo '<p>You'll recieve a mail here: ' . $email . '</p>';
global $current_user; get_currentuserinfo(); if (isset($_POST['email'])) { wp_update_user( array('ID' => $current_user->ID, 'user_email' => $_POST['email']) ); unset($current_user); get_currentuserinfo(); //just in case } echo '<p>You'll recieve a mail here: ' . $current_user->user_email . '</p>'; Now it should work, the problem was on the `get_currentuserinfo()` function, because it checks if the variable is already set and is an instace of `WP_User`, if it is, the function "aborts" (returns) and doesn't update the variable.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "post meta" }
Does WordPress create a new Linux user when creating a new WordPress blog? I wonder if WordPress creates a new Linux user when creating a new WordPress blog? I am a NodeJS developer, but from what I know PHP scripts can also have access to entire file system. That's why I think that WordPress creates a new sytem user for every blog. Is this true? If not, how do they manage access between two WordPress blogs?
Linux users have nothing to do with WordPress users. WordPress maintains its own user database, with its own permissions. The linux user PHP is running as is determined by the server setup, usually whatever user that Apache/Nginx/etc are running as. If your PHP can access the **entire** file system then you have a serious security issue and should contact your sysadmin/hosting
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, filesystem, linux" }
How to redirect unattached image attachments I'm currently redirecting all attachment images to their parent post with the following function: function attachment_redirect() { global $post; if ( is_attachment() && isset( $post->post_parent ) && is_numeric( $post->post_parent ) && ( $post->post_parent != 0 ) ) { wp_redirect( get_permalink( $post->post_parent ), 301 ); exit(); } } add_action( 'template_redirect', 'attachment_redirect' ); How can I redirect all images that have been uploaded to the media library but remain 'unattached'? My aim is to redirect these images to the homepage.
Posts that aren't attached have no parent, and posts with no parent have a parent of 0. So this: if ( is_attachment() && isset( $post->post_parent ) && is_numeric( $post->post_parent ) && ( $post->post_parent != 0 ) ) { becomes this: if ( is_attachment() && ( $post->post_parent == 0 ) ) {
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php" }
Custom form action hook I am writting a simple newsletter subscriber plugin. I created a widget with form: echo '<form action="'.home_url().'" method="post" name="subscriber_form">'; echo '<p><input type="email" name="subscriber_mail" value="" placeholder="'.__('Enter your email','my-text-domain').'" required /></p>'; echo '<input type="submit" name="subscriber_send" value="'.__('Subscribe','my-text-domain').'" class="Buttons">'; echo '</form>'; I could specify the action directly to the file to handle the form but I need wordpress to be loaded. Is there a hook (like with ajax) to point the form to or is there a way to correctly start the instance of wordpress inside the plugin? Thanks for feedback.
`admin_url( 'admin-post.php' )` is the non-ajax version of `admin_url( 'admin-ajax.php' )` Similar to `admin-ajax.php` it will fire one of four hooks: **Logged out users** * `admin_post_nopriv_{action}` (`$_REQUEST['action']` specified) * `admin_post_nopriv` ( **no** `$_REQUEST['action']` specified) **Logged in user** * `admin_post_{action}` (`$_REQUEST['action']` specified) * `admin_post` ( **no** `$_REQUEST['action']` specified) The 'action' can therefer bespecified as part of the target url (e.g. `admin_url( 'admin-ajax.php?action=my-action' )`) or as posted along with all the other data. The disadvantage to this is that if you need to return the user to the form (e.g. because of an error), you will need to redirect them, and so the browser will loose the data they entered. That's terrible UX, so I rarely use this.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "hooks, forms" }
Allow the access over wp-login.php I created a maintenace template, and redirected to the folder where it is located via the functions.php file inside the theme folder; this is the code: function maintenance_redirect(){ if( !is_user_logged_in()){ include("maintenance/index.html"); exit(); } } add_action( 'init' ,'maintenance_redirect' ); but i can't access to the log in page via wp-login.php or wp-admin/ beacause i get redirected to the maintenance page, how can i esclude from redirection the path of log in page? Thanks in advance :)
Use the hook `template_redirect` instead - this will ensure it only runs on the front-end of your site, and not for the admin, login, registration or signup pages. function wpse_159552_maintenance() { if ( ! is_front_page() ) { wp_redirect( home_url() ); exit; } include 'maintenance/index.html'; exit; } add_action( 'template_redirect', 'wpse_159552_maintenance' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, templates, redirect, maintenance" }
Weird issue with database migration and SSL links I want to move my database to my another mirror server (for testing & stuff). My original one is using SSL and I am forcing it to do so. When I migrate with DB Migrate plugin, the non-ssl server gets broken links. All links, became https. How can i fix this? Any ideas?
Found a problem. Basically there were 2 options that forced my permalinks to https: 1. Settings > General: change the site url from https to http. 2. SEO by Yoast plugin, under section permalinks needed to change Canonical Settings to force HTTP.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "database, migration, ssl" }
Copy and delete a directory with WordPress functions I have successfully used `copy_dir()` to copy a directory to a new location. How can I delete a directory using WordPress functions?
The method `rmdir()` \- source \- : /** * Delete a directory. * * @since 2.5.0 * * @param string $path Path to directory. * @param bool $recursive Optional. Whether to recursively remove files/directories. * Default false. * @return bool Whether directory is deleted successfully or not. */ public function rmdir( $path, $recursive = false ) { return false; } from the `WP_Filesystem_Base` class should work for that purpose. The method `rmdir()` is part of the classes that extend `WP_Filesystem_Base`, like `WP_Filesystem_Direct` and accordingly there is the `rmdir()` method in that class. Take a look at the the `wp-admin/includes` directory to inspect the other classes yourself. So just copy the directory with `copy_dir()` \- source \- and then remove it with above method. A bit more general information about the Filesystem API can be found at the codex page.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "functions, directory, wp filesystem" }
How to show page title in blog post of wordpress site I want to show the page title in single post page of wordpress theme. I tried to use `<?php echo get_the_title() ?>` but it returns the post title, not the page title. basically I want to show my page title, in this case "Blog" below my header area in single.php file. how do I make it?
> I want to show the page title in single post page What do you mean by "page title of a single post page" The title of a single post page will be the same as the current post being displayed. The retrieve and display the page title of a single post page, use the native function `single_post_title()`. Just add it where you need to display the title > ...I want to show my page title, in this case "Blog" below my header area in single.php file Blog **cannot** be the page title, except when your post's name is blog. If the name "Blog" is something else or derived from any other source, you'll need to reveal that source then If my answer doesn't answer your question, please file an edit and properly explain what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp title" }
How to add custom field option with menu? Please take a look at below image. !enter image description here Here we can see URL, Navigation Label & Title Attribute under Menu Structure >> Home. I need there a more option called "Data Description". I have a task to write menu code like below with wordpress. <a href="[URL]" data-description="[Data Description]">[Navigation Label]</a> Is there any option to display my menu dynamically like this? Also It should support "current-menu-item" class on current page. I'm a wordpress theme developer & also have some knowledge of plugins development, If there are any way please suggest me.
This link helps me to solve my problem. : <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, custom field, menus, admin menu" }
How To Remove Certain category Posts From the Blog Page I'd like to know, Is there any ways to remove certain category posts from the blog page. Actually, I own a technology blog and I'd like to implement free software directory or marketplace in my blog within download category. But The download category post will not display in the blog page and only accessible from download category. I have heard about some plugin but I trust codes instead of the plugin. Thanks in Advance :)
The correct way to do this is to make use of `pre_get_posts` which change the query vars just before the main query is executed. Here is an example from the codex to exclude categories from the home page/blog page. For a full list of available parameters and values that you can use with `pre_get_posts`, visit the `WP_Query` codex page function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1,-1347' ); } } add_action( 'pre_get_posts', 'exclude_category' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, categories" }