INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Is Partial SSL Possible? ( multisite ) I have recently been invited to the letsencrypt SSL beta, and have now spotted a potential problem. My main site tomjn.com is a multisite, and I have the opportunity to add certificates for tomjn.com and www.tomjn.com, but I also have other subdomains, subdomains i do not have SSL certificates for. Is it possible to have tomjn.com served over SSL via WordPress, but only tomjn.com? Or must I force all the blogs/sites in my install to use SSL? If so, how is this best done?
My solution in the end was to modify the `home` and `siteurl` options to include `https` in the url, rather than `http`, which set WordPress to use https by default for my main site, but not the others. As I acquire certificates for the other subdomains I can modify the options on those sites to enable SSL Additional server configuration to set up SSL only on nginx was necessary but that's server configuration not WordPress
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "multisite, ssl" }
How to write Hebrew characters? Our database is set to: define(‘DB_CHARSET’, ‘utf8’); define(‘DB_COLLATE’, ”); As a result, entered Hebrew characters in a post are turned into question marks (?) on saving of the post. What is the required procedure to have the database support Hebrew characters in Wordpress posts?
You need to check your mysql database charset and website charset. They should be same - utf8.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "database, language, encoding" }
Get parameters and custom page template My WP website have calendar page with custom page template. If i open mysite.com/cal i see calendar of current month, if i open **mysite.com/cal/?month=01 &year=2015** i see calendar for january. It works without any rewrite rules for every month in 2015 but for some reason for any other years i see error that there is no such page. Why does it happen? How can i solve it?
I found where problem was - i can't set other year. All i needed to do is to rename year parameter to something else - for example my_year.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "url rewriting, urls, page template, parameter" }
Include tags in WP_Query I found several posts about it. Others said that you cannot do it without a plugin and others that it is possible. However, I am not sure what is true :P This is my query and unfortunately, I cannot make it return objects with a certain tag. <?php global $query_string; $query_args = explode("&", $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode("=", $string); $search_query[$query_split[0]] = urldecode($query_split[1]); } $search = new WP_Query($search_query); ?> Any idea how I can modify the query to include also the tags without a plugin?
This solution may work for you also Include custom taxonomy term in search
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp query, search, tags" }
Why is my shortcode not working Im making a custom shortcode for my wordpress site and im just running through the example from the shortcode api for wordpress: function myshortcode() { $atts = shortcode_atts( array( 'custom_title' => 'Your Title', 'custom_message' => 'Your Message', ), $atts); return 'Test: ' . $atts['custom_title'] . ' ' . $atts['custom_message']; } add_shortcode('my-short','myshortcode'); The shortcode in my blog post is: [my-short custom_title="Test" custom_message="123 Roman Ridge"] but it outputs Test: Your Title Your Message there is nothing else in my blog post except the shortcode, any suggestions?
Note the following line in your function defintion: function myshortcode() { it's missing the input parameters `$atts` and `$content` so that's why you only get the default attribute values. Replace it with: function myshortcode( $atts = [], $content = '' ) {
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "plugin development, shortcode" }
Let users edit their role from the frontend Most site ask users to choose their role at registration (for example it can be "are you an athlete/student/worker/designer" and each of these would be a user role which would appear in a different directory) but I'd like to let them choose after registration. How can I do this ? Is their a way to let their change their role afterwards ?
You could make a widget that updates the role: 1. Widget has a drop down select input 2. Select input submits a Ajax call to backend 3. Backend Ajax call processor updades the user meta 4. Pass the User ID along with the role ID 5. Update user meta with `update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "user roles, directory" }
login trouble Wordpress can change IDs created by hoster site I have a big login trouble. In fact, I created a website via a hoster site that installed me Wordpress automatically. I had a login and password via the hoster. Without realizing I am connected to wordpress by a former identifiant (a blog that was lying still and that I not use) and I changed this former identifiant giving it the new ID that the site hoster gave me . Firstly how that it has happened, it should not. Second, and when I deleted the account created directly via wordpress, I asked Wordpress to send me my password but they told me that ID was not created by wordpress thus they can not initialize my password ??? what would I do?
Depending on the hosting company you're using you could access the database and modify the table for users. I've used phpMyAdmin to do this in the past but that would depend on if your hosting company allows you to use this. If you have access with phpMyAdmin go to `wp_users`: ![enter image description here]( Make sure your tab is in browse and click edit: ![enter image description here]( Enter your new password and click `Go`. In regards to a wrong install you should consult with your hosting company. If you dont have access to the database then I dont know what you can do except contact the hosting company.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "login" }
Maximum execution time exceeded while upgrading network on multisite local install Every time I try to hit "upgrade network" on my multisite install's dashboard I end up getting the following error message: Fatal error: Maximum execution time of 30 seconds exceeded in D:\...\www\wordpress\wp-includes\class-http.php on line 1595 Any idea how to fix this problem?
You network upgrade is taking too long to execute. You could mitigate the error by extending the execution time limit: 1. Increase `max_execution_time` in _php.ini_ 2. Set `max_execution_time` in script to a higher number `ini_set('max_execution_time', 300);` 3. Temporarily add this line in _index.php_ `set_time_limit(0);`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "upgrade" }
Why do templates contain so many PHP tag pairs? I have some PHP experience, but hardly any WP theme writing experience...I'm just starting the journey. All of the themes I have looked at so far in the .org repository have code that looks like this: <?php if (condition) { ?> ..some html <?php } else { ?> ..some other html <?php } ?> instead of: <?php if (condition) { echo ..some html } else { echo ..some other html } ?> I can see that when using an editor like notepad++ we'd rather have the html "naked" and not in an echo statement, to give the editor the ability to color-code and match up HTML tags with their ending tags, etc. But I see a lot of templates that have a TON of PHP code and very little HTML -- and they still wrap PHP tags around _every_ line of code. To me, that makes it hard to read. Is there a technical reason for that, or just a preference on the part of the developer?
As always, people copy paste whatever they learned from and IIRC the first style is the coding style of wordpress core. As you said yourself, when there is a big block of generated HTML it is easier to look at (and balance tags) under the first style, but pragmatic people will use the second whenever that is not the case. It is really just coding style preference nothing technical behind it.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 7, "tags": "php, templates, html" }
How do I include a partial from a directory below a wordpress theme directory? I have 3 themes set up right now and I need them all to inherit partials from the same source in order to update all three themes at the exact same time when I change any of those partials. I'm seeing that include/require (../../../includes/vital/partial.php); doesn't work from within single.php or any other other theme template file. the error I get is: Warning: include(): Failed opening '../../../includes/vital/partial.php' for inclusion (include_path='.:/usr/local/Cellar/php56/5.6.8/lib/php') in /Users/insertusername/Documents/Code/Projects/wordpress/wordpress-1/wp-content/themes/flowerz-mobile/single.php on line 7 How can I make this work? Thanks!
Don't ever use relative paths in wordpress. use `require(ABSPATH .'your path relative to wordpress root')`. There are also other useful constants and API for that but selecting one will depend on where exactly do yo want your common code to be. At the minimum it will make it easier to understand from the error message which file exactly is failing to open.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, themes, directory" }
I need to get an array from the wordpress database I need to convert this code //This creates an array from the database and allows us to use it later in the jquery //CREATE SQL STATEMENT $sql_locations = "SELECT * FROM tbllocations"; //EXECUTE SQL STATEMENT $rs_locations = mysqli_query($vconnection, $sql_locations); $rs_locations_rows = mysqli_fetch_assoc($rs_locations); foreach( $rs_locations as $rs_location ) { $markers[] = array( "{$rs_location['place']}, {$rs_location['city']}", $rs_location['long'], $rs_location['lat'] ); } to wordpress. I have created a custom post type that would save longitude and latitude inputs. Which database table would i need to look in to get these inputs and then run them through that for each loop? Will this work? D
Is this what you are asking for? Use it after the code you posted to create posts in loop and use thier ids to update meta fields. Replace "post_type" with your custom post type. foreach ($markers as $marker){ $post_id = wp_insert_post(array( "post_title" => "something", "post_type" => "your-type", "post_status" => "publish", //by default they are drafts // etc. )); update_post_meta($post_id, "latitude", $marker['lat']); update_post_meta($post_id, "longitude", $marker['long']); } After that you can get those fields by using get_post_meta()
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "database, javascript, php, google maps" }
custom post type and custom taxonomy I have a site with numerous custom post types that are created using a class. I was considering whether it was worth creating a custom taxonomy for each custom post type to offer a way of organizing and categorizing within that custom post type _-e.g_ terms and tags that only apply to that post type and not others (so keeping the vernacular separate). Would that be a sensible use of taxonomies as I've seen some quite confusing (mis)use of taxonomies its seems in Wordpress.
Yes. A taxonomy is simply a way to classify objects and organize them by shared characteristics (the taxonomy). Sounds like you have a perfect use case.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy" }
PHP Button Custom link At this part of code of a wp template I want to change the permalink url of the "Book Now" button to custom link example: "www.mywebsite.com" byt_render_field("description clearfix", "", "", $accommodation_description_html, '', false, true); if (!empty($current_url) && $current_url == $list_user_accommodations_url) byt_render_link_button($submit_accommodations_url . '?fesid=' . $accommodation_id, "gradient-button clearfix", "", __('Edit', 'bookyourtravel')); else byt_render_link_button($accommodation_obj->get_permalink(), "gradient-button clearfix", "", __('Book now', 'bookyourtravel'));
I'm not sure what `byt_render_link_button()` does, but I try this. <?php byt_render_field("description clearfix", "", "", $accommodation_description_html, '', false, true); if (!empty($current_url) && $current_url == $list_user_accommodations_url) { byt_render_link_button($submit_accommodations_url . '?fesid=' . $accommodation_id, "gradient-button clearfix", "", __('Edit', 'bookyourtravel')); } else { byt_render_link_button( ' "gradient-button clearfix", "", __('Book now', 'bookyourtravel') ); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "custom post types, php, permalinks, templates, links" }
How to access my WP site locally and publicly? On my wordpress server I have a Q&A form set up on my local network, but it can only be accessed publicly, how can I access it from home. * Wordpress server on local network * WordPress Address (URL) brandon.raspctl.com * Site Address (URL) brandon.raspctl.com * I am able to connect to it away from home * not able to connect to it at home
Try accessing it using a direct IP address: Example: < You may not even need the site name if it is the only site hosted from that server. Ok in that case then you need to get the direct link from outside, replace the server URL with the IP address and bingo you should be there internally. The reason the link redirects you is because your WordPress settings use the for its page direction in the permalinks and general areas.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization" }
Internal error 500 accessing Theme > Customize We have created a basic custom theme for WordPress. When trying to access Appearance > Customize from the backend we receive an internal error 500. I have checked the error logs and cannot find anything relating to this. The website is working fine, the theme is working fine as expected, just accessing the customize section. Do we need to include anything specific in the functions theme file to be allowed to access this section? Does a part of the theme have to be customizable in some way? I have tried various searches for this, although the basic 500 errors seem to come up a lot. I.e. htaccess, plugin issues.
Just in case anyone else finds this in the future. The issue was that we had an error/warning in our functions file. When accessing widgets we noticed the error/warning from the file. Resolved this, then the customizer link provided us with an on page error. The on page error linked to a reimplementation of a method from within a plugin. The plugin was overriding a core method so we removed it and now works as expected.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, themes, theme options, theme customizer" }
Custom Post Type categories at edit post not hierarchical I have created a custom post type and added a custom taxonomy like this: register_taxonomy( 'categories', 'ph_products', array( 'hierarchical' => true, 'show_admin_column' => true, 'label' => 'Products', 'query_var' => true, 'rewrite' => array( 'slug' => 'products', 'with_front' => false ) ) ); When I create some categories and child categories it looks right. But when I switch to create a post all the categories are on one level and not indented. So it seems its just a problem in the edit post page. For normal posts the hierarchies are displayed correctly in the sidebar when creating a new post. What am I missing?
It might be because you are using reserved term name as first argument; 'categories' is wordpress core taxonomy and you should use something else like 'ph_categories'. After that you will have to add those terms again. Reference: Codex
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy, hierarchical" }
How do you assign custom template for Posts page (under Front page displays setting) How do you assign custom template for Posts page (under Front page displays setting)? `Settings > Reading` in backend. I notice once I set Posts page to specific page, the Template dropdown on edit page disappears. Also tried `page-blog.php` but did not work. ![enter image description here](
I recommend bookmarking this Image from Wordpres Codex Template Hierarchy As you can see on it Blogs page uses `home.php` as template while front page is using `front-page.php`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, templates, page template" }
Where to put random functions? I have functions for setting default values when a new user signs up, functions for performance testing, functions for writing out a small icon to the admin tool bar, and so on. These functions are scattered around where I'm using them, which is in templates, plugins, and so on. Where should I be putting them? I know there is a `theme/functions.php` and a `wp-includes/functions.php` and that seems like the logical place to put them, but my hosting company is set to upgrade my installs to the latest versions. I don't want my code in the `functions.php` to be overwritten. What should I do?
`wp-includes/functions.php` is never a file you should modify. Any mention of adding something to `functions.php` is never referring to this file. Functions related to front-end display or theme behavior should go in your theme's `functions.php`. If the theme may potentially be updated, then you should be using a Child Theme to add functionality, and they should go in your child theme's `functions.php`. Child themes are update-safe - a core update will not overwrite a child theme. For any code that should persist regardless of active theme, those functions should go in your own plugin. Your own plugins are update-safe. Regardless of what option you choose, you should always have a local recent backup in case you need to restore things.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions" }
Why doesn't jQuery use $, and how can I get it do so (GLOBALLY)? I have a WordPress theme that includes jQuery, but for some reason the "$" doesn't let me call jQuery. I know I can wrap jQuery calls in an anonymous function, but I have other plugins that rely on the $ working, and I don't want to modify their code. So I need a way to make "$" work for jQuery, globally, across all JS in my site. My theme adds jQuery with this (in functions.php): function ss_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_style( 'ss-style', get_stylesheet_uri() ); } add_action( 'wp_enqueue_scripts', 'ss_scripts' ); So two questions: 1. Why doesn't jQuery default to the "$" when the script is added this way? 2. How can I make the $ use jQuery, globally, across my entire site?
> Why doesn't jQuery default to the "$" when the script is added this way? The `$` alias has been chosen by several different libraries an alias. This causes conflict if you try to use more than one library. It is a bit ridiculous, actually-- like several major corporations all deciding to use the same phone number. > How can I make the $ use jQuery, globally, across my entire site? WordPress load jQuery in noConflict mode to avoid the problems caused by the above foolish aliasing. You should not reintroduce those issues.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery, javascript" }
What is rich_editing? I wanted to learn more about shortcodes with button implementation since I do not use them much and I have been doing a lot of research on the topic and the questions and tutorials I run across use a conditional with `get_user_option( 'rich_editing' ) == 'true'`. I tried a search on the site but browsing through I didn't see anyone dive into the specifics and when I searched the codex it lands me on `get_userdata()` with: ![enter image description here]( So what is `rich_editing` actually doing if you are already using `if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ))`?
The `rich_editing` user option stores this check box value: ![rich editing]( wether or not do enable the visual editor for that particular user. If it's disabled then the content editor will look like this: ![no visual editor here](
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "plugin development, shortcode, user meta" }
How to require users not to be logged in for comments on single page only? I am trying to make my own guestbook out of default comments, but I normally require users to be logged in. In this case, I need WP not to require it. Is there a way to do it for single page? Thank you
Extremely not tested, based on overriding the global "users must login to comment" option (comment_registration) for a specific post function wpse208664_option_comment_registration($v) { if (is_single() && (get_the_ID() == your specific post ID)) $v = 0; return $v; } add_filter('option_comment_registration', 'wpse208664_option_comment_registration');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments" }
Find by post_meta, then sort by post_meta, then sort by date (wp_posts) I have a custom meta field that I find a list of posts from. This custom meta is a numerical attribute (1-10) and I need to sort by 1-10, but I also need to sort by post date. So if two items are both assigned a "1", then I need to fallback on post date (newest first). I'm having a hard time ordering by the fields from two different tables. This is what I've got so far... $query_args = array( 'posts_per_page' => 5, 'cat' => $category_id, 'post_status' => 'publish', 'meta_key' => 'featured', 'orderby' => 'meta_value_num', 'order' => 'ASC' ); How can I take the above query arguments and sort by post date from there?
Since version 4, you can order by multiple fields via an array: 'orderby' => array( 'meta_value_num' => 'ASC', 'date' => 'DESC' )
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, order, sql" }
WordPress security I created a website for my customer via wordpress and I uploaded it in their server ..we assume the user have the access in the whole server ..is it possible to protect this website from being used in other server by protect editing admin password in database or adding a script that required my permission.
No, and what you want is DRM and not security. The base of any measure of security is that only you have "root" level access to the server as the root user will be able in the end to overcome any DRM measure you try to implement. If a contract will not stop him from violating your rights (assuming you have them at all), nothing will stop him. If you want to restrict your user in such a away as you imply, you should not give him root/ftp access to the server.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, security" }
Current blog is returning ID of 1 instead of users blog ID? I'm trying to update an option for the network blog the user is on but get_current_blog_id() is returning 1 for every blog. I'm using the JSON-API plugin and I do the following: 1. user logs in at www.example.com/default_site. 2. everything seems to work fine except I get id of 1 for that method
This happened because WPMU has an admin account that defaults to the same URL as the install. So my admin user, who is also the default user, let's call him "adminUser", could log in at He could update, add new posts, whatever and his posts show up at: But when new user, let's call him, "JoeHermermerphermer", comes along, he can register and login at: but after login he needs to make calls to his own site URL: The website would probably have redirected him to his site on login, but when using a plugin, I must manually redirect calls to the new URL. It seems the `get_current_blog()` method looks at the URL you are on.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite" }
How to create a Full RSS feed (secret URL) for certain users, short for the rest I'm running a Patreon campaign for my blog and **one of the rewards will be a full RSS** available for users that contribute to that campaign, with the rest having only a short RSS Feed. I'm experimenting with the SB RSS Feed Plus plugin, but I've just installed it and I'm not sure it will do what I ask. I wonder if there is an alternative to get what I want, specifically: **A special, secret URL for the full RSS feed** I know there are services that can provide the full RSS feed from the short one (I guess it's impossible to block them) but anyway, I'd like to set that full RSS feed as a "premium" advantage for Patreon supporters. I wouldn't like to implemente a Membership to my blog (I think this overcomplicates everything) and I'd like if this is possible easily.
## A "secret" full text feed Here's a demo plugin that gives you a full text feed at: example.tld/secretfeed/ Just remember to flush the rewrite rules, e.g. by visiting the _Settings/Permalinks_ page: <?php /** * Plugin Name: Secret Full Text Feed * Plugin URI: */ add_action( 'init', function() { add_feed( 'secretfeed', 'do_feed_rss2' ); }); add_action( 'pre_get_posts', function( \WP_Query $q ) { if( $q->is_feed( 'secretfeed' ) ) add_filter( 'option_rss_use_excerpt', '__return_false' ); } ); You can then adjust the `secretfeed` slug to your needs.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "rss, membership, premium" }
Locked/Unlocked in title This should be incredibly easy, but I'm missing something. This code should simply work if they have entered their password into a password protected post/page. The idea is to remind them it is protected. However... I can't get it to work at all. The if statement never returns true. For some reason, I don't think the function is getting $post. function unlocked() { if(!empty($post->post_password) && !post_password_required()) { echo 'unlocked icon reminding them this was protected and they put in their password already'; } }
Your function will never "get" `$post` as this is not how functions work. Functions cannot pull anything into itself by itself. If you have debug turned on, you will get a definite bug notice that `$post` in undefined..... You would need to invoke the `$post` global inside your function for anything to work that relies on the `$post` global, so the following would work function unlocked() { global $post; if(!empty($post->post_password) && !post_password_required()) { echo 'unlocked icon reminding them this was protected and they put in their password already'; } }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, password" }
Sort WP_Query with numeric custom field I have added a numeric field (called 'video_order') to a certain post type, via ACF. I would like to sort the list of posts, by that numeric field. I have made sure to go through the posts and give them all a value. This is the Query i have tried, which does not seem to work (there is just no sorting based on that numeric field) Can someone suggest something? Thanks! $args = array( 'post_type' => 'post_sermons', 'post_status' => 'publish', 'posts_per_page' => ot_get_option('wpl_sermon_per_page'), 'paged'=> $paged, 'orderby' => 'video_order', 'order' => 'ASC' );
Your meta key should be specified as the `meta_key` argument, and `orderby` should be `meta_value_num`: $args = array( 'post_type' => 'post_sermons', 'post_status' => 'publish', 'posts_per_page' => ot_get_option('wpl_sermon_per_page'), 'paged'=> $paged, 'meta_key' => 'video_order', 'orderby' => 'meta_value_num', 'order' => 'ASC' ); See `WP_Query` for explanations of query arguments.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "custom field, sort" }
Get previous posts list I'll give up. Have searched and searched and tried and tried... Can't find any solution to list previous posts. On a single post: I want to show a list of the 10 previous posts, the 10 before the current post. So, not just a two prev and next links. Not the most recent posts that is. A list of the the 10 previous posts before the current post you are visiting. I'm trying to make a query and comparing `post_date` lower than `get_the_date('Y-m-d H:i:s')`. But it's not working. I guess post_date isn't an allowed key to use in `'compare'`. Any ideas? **Edit:** The code right now: <?php $posts_args = array( 'posts_per_page' => 10 , 'meta_query'=> array( array( 'key' => 'post_date' , 'compare' => '<' , 'value' => get_the_date('Y-m-d H:i:s') ) ) ); $myposts = query_posts($posts_args); ?>
Did you chceck the Codex Date Parameters ? Expecially the 'before' param. It works like this: $date = get_the_date('Y-m-d H:i:s'); $args = array( 'date_query' => array( array( 'before' => $date ), ), 'posts_per_page' => 10, ); $query = new WP_Query( $args );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query, date, previous, comparison" }
How to disable content pagination? I want to totally disable this functionality from WordPress because I'm implementing my own version of this with Javascript. When I try to grab all the content in a post via the `get_the_content()` or `the_content()` it gives me only the first page, since the content has the page breaks. When I use `$post->the_content` I get the full post but it's not formatted with HTML tags. I don't want to have to add those myself programatically. So I either need to get all the content already formatted - the way to do this is unknown to me at the moment or disable `wp_page_links()` so it doesn't paginate my posts.
**EDIT -** Now that 4.4 is out, you should use the `content_pagination` filter. See birgire's answer below. * * * You can add formatting to raw post content by applying the content filters directly to `$post->post_content`: echo apply_filters( 'the_content', $post->post_content ); This will bypass pagination by not using the `get_the_content` function, which is what `the_content` uses internally to retrieve the current page's content for multipage posts. You can prevent `wp_link_pages` from outputting anything by applying a filter to its output before the function is called and using the `__return_empty_string` helper function: add_filter( 'wp_link_pages', '__return_empty_string' );
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "posts, pagination, the content" }
Rewrite URL to remap WordPress Permalink I'm moving my WordPress site to a new host, and in the process I want to make a one time change to the Permalinks. I want to rewrite the URLs from `/2015/11/sample-post/` to `/sample-post/` but how can I accomplish that?
The most efficient way to accomplish this would be to change the structure to `/%postname%/` and add a 301 redirect to your .htaccess file for the old structure: RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(?!page/)(.+)$ Change `example.com` to your domain and add the redirect above the `# BEGIN WordPress` directive so it won't be removed if WordPress updates the file. EDIT- redirect /yyyy/mm/dd/postname RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "url rewriting, apache, linux" }
WP: adding Javascript to specific woo commerce pages I'm developing an eCommerce site using Woo-Commerce, i'm hoping to introduce some JavaScript to my sale pages only, in the name of a finance slider. What is the best way to go about including a specific piece of JavaScript on my Woo-Commerce sale page only. I'm new to WP so apologies if this is obvious, google didn't help though. Thanks
Add this to your themes functions.php. add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_scripts' ); function my_theme_enqueue_scripts() { if ( is_page('your-specific-page') ) { wp_enqueue_script( 'script-name', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ) ); } } Documentation for wp_enqueue_scripts
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, woocommerce offtopic" }
How to disable wordpress page rewrite rule? I am having a problem with some rewrite rules. I am using a plugin that makes requests like this: `/pluginname?nonce=123456789&action=submit` the problem with this is that my wp installation takes the part up to `&` as a variable itself `q=/pluginname?nonce=123456789` which it is not supposed to do... I tried using a broader rewrite rule like this `add_rewrite_rule( "pluginname/?(.*)", 'index.php?$matches[1]', 'top' );` but it does not work...
It was caused by the nginx rewrite rules, I thought I checked them but eventually I missed the most obvious one :s
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, permalinks, rewrite rules" }
Should I use Filesystem API for reading files or listing directories? I know that i should use Filesystem API to write files and I understand why but is there any difference if I read file with wp_filesystem or plain PHP? And what about listing directories? Consider this example: In wp-content I have my-plugin-templates-folder which has to be listed by my-plugin. Does anybody met with configuration which disallow webserver process list this directory so I should use wp_filesystem?
No you don't, and not even sure if you can use it for listing files in directories. The only limitation on reading files is that they will be readable to the web server, and obviously plugin directories has to be readable for the web server to be able to read the PHP files. Now, if you are trying to read something outside of the wordpress file structure you might need to use the filesystem API.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filesystem, wp filesystem, filesystem api" }
How can I move Customizer menu item to first level in WP Dashboard? How can I move **Customize** menu item from **Appearance** menu to first level menu items in WordPress dashboard so it would be below Appareance menu? Also how can I change the name Customize?
The function below should help you. It removes the default menu item from the "Apperance" menu item and a new menu item to the Dashboard. add_action( 'admin_menu', 'fb_customize_admin_menu_hide', 999 ); function fb_customize_admin_menu_hide(){ global $submenu; // Remove Appearance - Customize Menu unset( $submenu[ 'themes.php' ][ 6 ] ); // Create URL. $customize_url = add_query_arg( 'return', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'customize.php' ); // Add sub menu page to the Dashboard menu. add_dashboard_page( __( 'Customize' ), __( 'Customize' ), 'customize', esc_url( $customize_url ), '' ); } You should copy this in a small plugin and activate in your installation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "admin menu, dashboard, theme customizer" }
is there a benefit in using a constant over get_stylesheet_directory_uri? Is there any benefit perfomance wise when defining a constant in the wp-config.php like so <php define('PATH_TO_THEME', get_stylesheet_directory_uri() ); ?> and then referring to `PATH_TO_THEME` instead using `get_stylesheet_directory_uri()` multiple times? I got this from a wordpress handbook, saying that when you call this function multiple times it consumes more performance in comparison to using a constant like PATH_TO_THEME. Is that true? And why? Or does it only give a performance boost when using an absolute uri to define the constant like so `<php define('PATH_TO_THEME', ' ); ?> `This of course would mean you had to change the uri anytime the url of the website or the location of the stylesheet directory changed.
You can read up the source code of theme.php where `get_stylesheet_directory_uri()` is defined, inside you'll see a `str_replace()` wich is consuming additional resources on each request. The best way to avoid this is to define a variable or constant that contains the path. In that case it is only called once. <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, performance, constants" }
How might I use $_SERVER['REMOTE_USER'] in the context of OpenAM Single SIgn on to allow users to authenticate? At an institution they use Sun's OpenAM SSO Enterprise, which after a successful login with the inistuations' SSO, places the username inside of [$_SERVER['REMOTE_USER']]( First, is it possible to take advanced of this, supplanting the WP login functionality in favor of using SSO? If this is possible, what is a best-practice method of doing so? Is there a preferred plugin which already has such functionality built?
I stumbled upon this module called OpenAM Authentication that I'm going to experiment with on a development server. Merely reading the plugin's FAQ page has me very hopeful
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "single sign on" }
Disconnect automattically after X minutes I recently discovered that if I don't disconnect myself from WordPress, my session could last for more than a day. I wondered what could I do to set a maximum time of inactivity on the site, after which the user would be logged out. I guess that has something to do with the validity of a cookie, but I'm not sure about that. How can I force a disconnect after a certain amount of time?
By default, the "Remember Me" checkbox makes you get remembered for 14 days. This is filterable though. add below code in your theme `functions.php` where 31556926 = 1 year in seconds This code will change that value: add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' ); function keep_me_logged_in_for_1_year( $expirein ) { return 31556926; // 1 year in seconds }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "cookies, session, logout" }
Manipulating cookie on specific taxonomy archive page I have this code to set cookie when user on the taxonomy archive page called 'term-country' if (is_tax('term-country')) add_action('init', 'my_setcookie'); // my_setcookie() set the cookie on the domain and directory WP is installed on function my_setcookie(){ $path = parse_url(get_option('siteurl'), PHP_URL_PATH); $host = parse_url(get_option('siteurl'), PHP_URL_HOST); $expiry = strtotime('+1 month'); setcookie('location', 'my_cookie_value_3', $expiry, $path, $host); } when I add the is_tax() function the code will not work when I remove the is_tax() function the code will work is there any issues with my code ?
After googling around I found the correct way to do it by using the 'wp' hook if (is_tax('term-country')) add_action('wp', 'my_setcookie'); // my_setcookie() set the cookie on the domain and directory WP is installed on function my_setcookie(){ $path = parse_url(get_option('siteurl'), PHP_URL_PATH); $host = parse_url(get_option('siteurl'), PHP_URL_HOST); $expiry = strtotime('+1 month'); setcookie('location', 'my_cookie_value_3', $expiry, $path, $host); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom taxonomy, conditional tags, cookies" }
Url wordpress rewrite In wordpress i have created a custom page called `mail.php` inside a folder `form_support`, my original url is ` i created htaccess file with rewriting rule : # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^mail$ /form_support/mail.php [L] </IfModule> # END WordPress i upload the htaccess file inside the folder `form_support` but when i call the `mail.php` page i dont get the rewrite url as mentioned above is there any thing i have missed ? my files -wp-admin -wp-content -wp-includes -form_support - mail.php - .htaccess
You don't need to create a folder. And create a file inside your theme with starting content of following one <?php /* Template Name: Mail Page */ // here your mail page content. ?> Now goto backend and `pages-> Add New`. Title your page and select a Template `Mail Page`. Now you can write your code on the template file. It will take effect.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "url rewriting, htaccess" }
Where WordPress Stores The Custom Fields Values I have a custom Post type called product which has a Methabox with a Custom Field Called `Price` I entered `$` for some of the products and I need to remove them from the WP table. Now can you please let me know how I can do that? I mean I need to know which table is storing the data from Metaboxes? **Update** add_action( 'add_meta_boxes', 'product_details_mtbox' ); function product_details_mtbox() { foreach( $post_types as $post_type ){ add_meta_box( "product-detail", "Product Details ", "render_mtbox", $post_type, "normal", "high" ); } }
In case you use native custom fields, you should look for them in wp_postmeta table (your table prefix can be different than 'wp').
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, custom field, metabox" }
Deprecated: mysql_connect() I have a project to upgrade Wordpress from 3.6.1 to 4.3.1. I've installed WAMPserver 2.5, and deployed the Wordpress site locally, but when I load the local website, I receive: > ( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\site\wp-includes\wp-db.php on line 1142 `\wp-includes\wp-db.php` contains the following @ line 1141: if ( WP_DEBUG ) { $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } else { $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } Advice on where to go from here appreciated.
Go to your WAMP settings and enable php_mysqli extension. You can do that within the toolbar menu on the right. Just right click on the WAMP icon and go to PHP extensions menu. PHP 5.5 will warn about the deprecated mysql driver functions. Turn off warnings by setting Debug to false in the `wp-config.php`, or use a database layer such as this plugin.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "localhost" }
How to test if there are no more previous or next image on attachment page? I have a `next_image_link` and `previous_image_link` as a navigation on my image.php but I want the first and last image to echo greyed out text (disabled button) to show prev button and next button. Right now, my code doesn't echo it when you are in the first or last image. < | **next >** I want to display something like this ( **where the bold text is a link** ) when you are in the first image < previous | **next >** And like this when you are in the last **< previous** | next > Currenty, I have this code: <?php next_image_link( false, '<div class="next-image">' . '<i class="fa fa-angle-left"></i> <span>PREV</span>' . '</div>' ); previous_image_link( false, '<div class="previous-image">' . '<span>NEXT</span> <i class="fa fa-angle-right"></i>' . '</div>' ); ?>
You need to use the adjacent image link filters, defined in the source of `adjacent_image_link()` function. Example: add_filter( "next_image_link", "cyb_next_image_link", 10, 4 ); function cyb_next_image_link( $output, $attachment_id, $size, $text ) { if( $output == '' ) { return '<div class="next-image"><span>NEXT</span> <i class="fa fa-angle-right"></i></div>'; } return $output; } add_filter( "previous_image_link", "cyb_previous_image_link", 10, 4 ); function cyb_previous_image_link( $output, $attachment_id, $size, $text ) { if( $output == '' ) { return '<div class="previous-image"><span>PREV</span> <i class="fa fa-angle-right"></i></div>'; } return $output; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, attachments" }
how to stop the shaking effect on my homepage This is my < Password: ireland Please check the attachment for better understanding. < This part of my website on my homepage, is giving a shaking effect when I hover over it. Please help me ASAP. Thanks.
This is what causes the "shaking effect" : #main section:hover At line 77 in this file So whenever you hover the section, the width changes and you are not hovering the section anymore, and this goes on..
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, html" }
How to display widgets inside a page content without a plugin? I want to build a homepage where I can show posts gathered from different categories and having the ability to choose such categories from the admin. I was thinking to use widgets for this. Is the right choice or is there a better way to do it? I've found this plugin which seems to do what I need, but if possible I would prefer avoiding the use of a plugin.
In order to register dynamic zones, you can follow theses steps : * Create a template for your home page * Assign that template to a page * Define that page as the Home page in Settings->reading * Register sidebar in your functions.php by using this function * Call the sidebar in your home template In order to call your sidebar, use dynamic_sidebar. So if you named your sidebar with the id "home-sidebar-1", you can call it this way : <?php dynamic_sidebar('home-sidebar-1') ?> You can add as many sidebar as you have declared in your functions.php
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, widgets, post content" }
Using 'get_template_directory_uri' correctly I have a woo-commerce child theme set up. In the functions.php file I am loading an additional tab. The function which loads the tab looks like this: function woo_finance_tab_content() { echo '<h2>Additional Tab</h2>'; } I'm attempting to load several php files, within this function. What is the correct way to do this though? If I have 'test.php' which I want to load inside the function, is it simply a case of using: echo "get_template_directory_uri(/woocommerce/single-product/test.php)";
`get_template_directory_uri()`, as the name suggests, gets the _URI_ of the theme. You want the filesystem path, which is `get_template_directory()`: <?php require get_template_directory() . '/woocommerce/single-product/test.php' ?> Better yet, use the WordPress template loading system: <?php locate_template( 'woocommerce/single-product/test.php', true /* Locate AND load the file */ ) ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development" }
How to create a dashboard for logged-in users with custom functionality? I am developing a Wordpress website in which each logged-in user should have a dashboard from which (s)he can upload video files. Each user has an upload limit of X GB. He also should be capable of seeing the amount of his remaining space. How should i create that dashboard? Is there a plugin or i should write my own PHP code ?
This is not a question that has any one particular answer. It all depends on specifically, what you are trying to achieve. You probably will not find a plugin that does exactly what you want without some heavy customization anyway, and I think that it will probably be easier to write your own plugin or custom theme functionality. I you have never done something like that before the codex is good a place to start.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, php, uploads, javascript, plugin recommendation" }
How to use Amazon Elastic Transcoder from Wordpress using AWS SDK for PHP? Use Case: The user uploads his video from the frontend of my website in any format he wants to Amazon S3. Now I want to covenrt that video file to MPEG-4 using Amazon Elastic Transcoder by applying AWS SDK for PHP. What is the best practice to do that if it is possible ?
1. Create a plugin to output the form using shortcode 2. Submit form using Ajax call 3. Fire off AWS-SDK calls within the form Ajax handler 4. Poll for Elastic Transcode job status, but SNS is preferrable 5. Push end result to Frontend User via Websocket or Email
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, plugin development, javascript" }
Blank white space where header was So I'm working on my website and as you see on all the pages there is a white space between the menu and the content on any page. How do I remove this whitespace or hide it? I think the space was reserved for the page title which I hid on all my pages but that space really bothers me.
I am not sure which white area you mean (the one above the line?) but that can be done by adding the following to your CSS: header.page-header { display:none; } div.entry-content { margin:0 auto; } Ideally do this in a child theme.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, css" }
Is it possible to filter the main loop to exclude posts from a specific category? The question is the same as the title. I'm talking about the default loop on the blog page / home page. I am using a network blog and must apply it to all blogs.
You still are going to make use of `pre_get_posts` to alter the main query query vars before the main query actually runs. The blog page/homepage can be targeted with the `is_home()` conditional tag add_action( 'pre_get_posts', function ( $q ) { if ( is_home() // Only targets the home/blog page && $q->is_main_query() // Only targets the main query ) { // Works on build in taxonomy category, for custom taxonomies, use a tax_query $q->set( 'cat', -1 ); // Change with correct category ID, minus sign means remove } }, PHP_MAX_INT ): I would add this into a plugin which you can activate ( _as Super Admin_ ) as a network plugin across the entire network
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, multisite, filters" }
Everytime I create my Events page, it shows up as an archive post instead of an actual page I had an events page on my site's main menu in which I attempted to adjust some css when to my horror, I discovered the page appeared as an archive. I checked in the specific page in question in the "Pages" container in "WP-Admin". It appears as a page in there. I deleted the page anyway and created a new Events page. Same thing. It appears as post/archive rather than a page. So my question is how I can turn this post into a page? All of the other menu items appear normally as pages. Here is the page in question: < Thanks!
It's possible that your theme or a plugin has an override for any page called events. Check your theme folder for `page-events.php`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, custom post type archives" }
Script not working in post content I have this code: Search: <input type="text" id="fname" onkeyup="myfunction()"> <a id="sear" href="" target="_blank">Search</a> <script> function myFunction() { var x = document.getElementById("fname").value; var url = " document.getElementById("sear").href=url; } </script> This code is changing into the following code when I add it to wordpress page editor and is not working. Search: <input id="fname" type="text" /> <a id="sear" target="_blank"></a>Search <script>// <![CDATA[ function myFunction() { var x = document.getElementById("fname").value; var url = " document.getElementById("sear").href=url; } // ]]></script> Is there a solution to make it work?
Put this markup where you would like to before footer. you can put this markup in page editor text mode too. But doing so will remain in that page alone. so place it in template files. Search: <input type="text" id="fname" > <a id="sear" href="" target="_blank">Search</a> write a function and hook it to `wp_footer`, place the code in **funcitons.php**. function output_custom_script(){ ?> <script> document.getElementById('fname').addEventListener('keyup', function() { var x = document.getElementById("fname").value; var url = " document.getElementById("sear").href=url; }, false); </script> <?php } add_action('wp_footer','output_custom_script'); Check this Js Fiddle
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "javascript" }
Moving Wordpress from host without FTP? I have a website hosted with service A which do not provide FTP access, and I would like to move it to another host B which provides FTP access. Is there any way to move? Traditional Archive,Download, and Upload is useless, since site is pretty large(2 GB). I've tried getting some most-popular plugins, but none seems to do the job. Also `max_execution_time` is 30 secs Any suggestions?
in your case - i will suggest you to use this plugin : < This plugin can make the backup of the site on Google drive,Dropbox amazon and etc, and after that you can sync your site with cloud (your old site and new site will be connected via cloud). So you don't need to download and upload the site again.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "plugins, admin, hosting, ftp, clone site" }
JavaScript in page doesn't open new window I have this code: Search: <input type="text" id="fname" onkeyup="myfunction()"> <a id="sear" href="" target="_blank">Search</a> <script> function myFunction() { var x = document.getElementById("fname").value; var url = " document.getElementById("sear").href=url; } </script> I have implemented this in WordPress and the link is now pointing to the same page rather than opening the google search page.
You have a typo in `onkeyup="myfunction()"`. Your function is named myFunction, not myfunction (function names are case sensitive).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "javascript" }
Show one post per author and limit query to 8 posts I want to show 8 recent products from multiple authors on the frontpage. Need to show 1 recent product per author. Currently i'm using basic wp query to show recent 8 products. $args = array ( 'post_type' => array( 'product' ), 'posts_per_page' => '8', 'order' => 'DESC', 'orderby' => 'date', ); // The Query $query = new WP_Query( $args ); What's the best way to achieve this?
I believe that you can achieve this effect by grouping the query by author ID, which will require a filter(mostly cribbed from the Codex): function my_posts_groupby($groupby) { global $wpdb; $groupby = "{$wpdb->posts}.post_author"; return $groupby; } add_filter( 'posts_groupby', 'my_posts_groupby' ); If you have less than 8 authors, however, this won't work. (You will get a number of results equal to your number of authors.) If that is the case you will need much more complicated logic and a much more complicated code.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "wp query, author, array, recent posts" }
Why does WordPress have more than one salt? I guess I am exposing some lack of security knowledge here, but shouldn't it be enough to have one salt? Why are four different salts necessary? define('AUTH_SALT', 'z(ly|p-aeKf^I~OfOUUIL&Y?C5Z.iu|L}kY%dvclq.h9n`)MlZe6'); define('SECURE_AUTH_SALT', 'NIY8g>=l9y~eV~WLu 3n>UG#3wSl4YfT%;z9`7m9Gk/k_Vn4`ej8'); define('LOGGED_IN_SALT', '<-[R@, I;m%n*9G?CU1a:))pEAa/r5X5@pT`cO2H|c2&x~G<p*3T:-5v<N'); define('NONCE_SALT', 'm(-0:+r0a%z~a:2F;]-geM$9~!4j(q3QdpkmB7;P+ZYYw7Rdy{97fS'); (Don't worry, values mangled and it is a local site.)
I posted the question on the wordpress slack and the answer I got < is that the difference is semantic and not practical and there is no reason to prefer the usage of one over the others (except for semantics of course)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 9, "tags": "security" }
is there any hooks or action to fire function of insert into post in media library? I am seeking for help to find the action or hook in order to fire function **insert into post** in media library. I did create a new tab for my videos and would like to insert my converted video by clicking an a tag or button to embed video into the WordPress editor. Please help thank you
The hook is `media_send_to_editor`. From the source of core. apply_filters ( 'media_send_to_editor', string $html, int $send_id, array $attachment ) Filter the HTML markup for a media item sent to the editor.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "media library, wp editor" }
Is it possible to sort metabox teaxtarea values? Textarea is on an options page, is it possible to sort the values within that textarea by alpha? I looked in the Codex but do not see any mention of sorting these values.
$values = get_option( 'option_name') // Create array from string $values_array = explode( PHP_EOL, $values ); sort( $values_array ); // Create string from sorted array $sorted_values = implode( PHP_EOL, $values_array ); Read more about the sort function
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, plugin development, metabox, options" }
Force TinyMCE editor's "Toolbar Toggle" to be automatically chosen & expanded A common problem we have with new Wordpress installations and particularly new users, is that their "Toolbar Toggle" button is not selected by default, and therefore the second line of the editor icons don't show. Is there a way to force this option to always be selected? ![Toolbar Toggle icon](
Add below function in your activated theme's functions.php file. function changeMceDefaults($in) { // customize the buttons $in['theme_advanced_buttons1'] = 'bold,italic,underline,bullist,numlist,hr,blockquote,link,unlink,justifyleft,justifycenter,justifyright,justifyfull,outdent,indent'; $in['theme_advanced_buttons2'] = 'formatselect,pastetext,pasteword,charmap,undo,redo'; // Keep the "kitchen sink" open $in[ 'wordpress_adv_hidden' ] = FALSE; return $in; } add_filter( 'tiny_mce_before_init', 'changeMceDefaults' );
stackexchange-wordpress
{ "answer_score": 9, "question_score": 5, "tags": "editor" }
Get all images out of the posts content I try to get all images out of the content-area of a post. I already tried this $imgs = get_posts(array( 'post_type' => 'attachment', 'post_per_page' => -1, 'post_parent' => $thread->ID )); But this only returns the featured image / the post thumbnail. I also have tried $imgs = get_post_galleries_images($thread->ID); foreach($imgs as $img){ echo $img; } But this returns nothing. Any idea how I can get the images out of the content? Thanks!
You can use DOMDocument class $doc = new DOMDocument(); $doc->loadHTML($post->post_content); $images = $document->getElementsByTagName('img');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, images" }
How does WordPress official repository estimate 'Active Installs' of a plugin? ![enter image description here]( Few months ago, WordPress official repository started to show number of 'Active Installs' of plugins. How is it estimated? For example, this plugin is downloaded 2,365 times and it shows **Active Installs:** 100+ Again, this plugins is downloaded 437 times only with same amount of **Active Installs:**!
Short answer: the update API. Whenever your WordPress install makes an update check, it'll ping wordpress.org with information about all the plugins you have, versions etc., but also whether they are currently activated or not - they then aggregate all this data from all active WordPress installs and hey presto, you get an idea of how "used" the plugin actually is.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 6, "tags": "plugins" }
Which is the correct way to migrate content from single WP to WP multisite I have an existing and working normal (not multisite) WP installation. Now I've created a new WP MultiSite installation and successfully set up 2 independent sites (both empty). Now I would like to clone the content from the old site to one of the site within the new multisite installation. Here is what I've done so far: * Upgraded the old site to have the very same WP version as the new. * Installed the very same version theme and plugins on the new site. * Looked into the DB tables, with no particular result... I see the DB structure is different for the new site to allow the multisite functionality. So obviously a db export/import will not work. I've also evaluated the possibility to upgrade the old site to be multisite, but that is not possible for various non technical reasons. What would be the correct solution to move my old site under to a site within the new multisite installation?
The WP importer should do the job for you. You may need to install it first. Backup. Backup. Backup. Then, from your current single site: Tools > Export > All Content > Download Then from the new location on your multi-site, Tools > Import > locate the export file and adjust options to your needs. Note - you will need to still take care of settings like widgets, setting up your menu locations and possibly a few other tasks depending on how your theme was written. There are many horror stories out there about the WP import/export tool. Some are true but most problems occur (in my experience) when doing partial content. In this case you are moving everything but your mileage may vary.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, import, export" }
How to remove a date from wordpress post djeddiedavid.info this is my website i want to remove a date that show on wordpress posts anyone help me ? ![enter image description here]( date that show on the bottom of DJ upcoming event
Try adding this to your CSS: .latest-post h4 + p { display: none; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "posts, themes, date" }
How to echo billing phone number under My Account in Woocommerce? We're wish to get customer's `billing_phone` number & then put it under "My Account" or "My Address" section. This way, our billing support can look up for a number to call from the front-end, w/o navigating into order management. Tried using `phone' => get_user_meta( $customer_id, $name . '_phone', true )` in my-address.php, but that isn't working. Any leads? Thank you.
You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure `$customer_id` is the ID of the user - you probably want `get_current_user_id()` instead.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 2, "tags": "woocommerce offtopic, user meta" }
Call custom field using php function the_alt_title($title= '') { $page = get_page_by_title($title); if ($p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true)) { $title = $p; } return $title; } add_filter('the_title', 'the_alt_title', 10, 1); My theme uses something called `alternate index title` and I also have the above custom function in my `functions.php` I presume the `alternate index title` is recognised as a custom field in wordpress? How can I call the `alternate index title` using php code on a page?
The answer is in your question: <?php $index_title = get_post_meta( get_the_ID(), '_x_entry_alternate_index_title', true ) ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions" }
How to allow only two (or more) users access to a plugin I need to allow two specific users, not groups, to use a certain plugin that is listed in the admin menu area. I have this code which allows one user (user id = 2) to see the plugin : add_menu_page( 'My Plugin Page', __('My Plugin Page', 'my-plugin-page'), 2, 'afp', 'mp_items_page', 'dashicons-admin-site', '101.1' ); I know I can use roles but that allows all users in that group to access the plugins page which is no good to me. One of the users I need to add is admin, the other is an author.
You can create a new user role or set user access level, if you wanted for large group of user. If not you just go with the normal way of adding the menu. But in printing the admin page just make sure that current user is what you are expecting to see the page. EG: add_menu_page( $page_title, $menu_title, $capability, $menu_slug, 'sample_function', $icon_url, $position ); function sample_funtion(){ $allowed_user_list = array(2,18); $current_user_ID = get_current_user_id(); if(in_array($current_user_ID,$allowed_user_list)){ //now print everything you want. Only allowed user will see it } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, users" }
Add additional templates to the templates drop down on add page menu I'd like to add a custom page template to the drop down menu shown in the picture. ![]( Had a good google at this but couldn't find anything, was too hard to form a concise query. Thanks for reading
Do you want to add this template via a plugin or using the theme? If you want to use the theme you need several things: 1. The PHP file which will be responsible for the page. The file itself can be named in two ways: `page-{slug}.php` or `page-{id}.php`. Here is an explanation what each one of them does. 2. You need to add the template name. Right after the opening `<?php` tag you need to add: /* Template Name: Your Template Name */ This name will be also used in the drop down. 3\. You need to code the logic for the template. Here is a good article on page templates.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "page template" }
How to edit plugin's html? Hello Dear Wordpress Developers, I'm using Awesome Sticky Header by DevCanyon plugin on my website. I want to edit this plugin's html. Because with plugin's settings only thing that I can add is menu's. I want to add custom html. like search bar or something. ps: English is not my native language. Sorry about that.
You should have the option to edit any plugin's code from the plugins screen. Under the name of each plugin you should see an Edit link which gives you access to the plugin code. Any changes that you make to the plugin will be completely wiped out when the plugin updates unless you ensure that you disable updates.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, customization, html" }
How to disable wordpress cron jobs for a subsite? Is there a way to disable the execution of all the cron jobs of a particular subsite in a wordpress multisite installation?
this filter does the trick: `add_filter('schedule_event', '__return_false'); `
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, wp cron" }
How to use add_action("wpcf7_before_send_mail" outside wp loop? I am trying to trigger an add_action hook (add_action("wpcf7_before_send_mail", "add_data_to_custom_table");) from outside the wordpress loop. The add_action hook is defined in theme's functions-custom.php. in domain.com/test.php i have define('WP_USE_THEMES', false); define('WP_CUSTOM_TABLE', 'test_table'); /** Loads the WordPress Environment and Template */ require( '../wp/wp-blog-header.php' ); include('../wp/wp-content/themes/customtheme/incs/functions-custom.php'); <?php echo do_shortcode('[contact-form-7 id="417" title="Test Contact Form"]'); ?> In this setup the add_action hook is not working. If however i move the add_action hook definition to the theme's functions.php it does work. My question: how can i include a functions-custom.php file outside the wordpress loop with working add_actions without including it from the theme's functions.php???
Just simply put your `add_action` hook in a simple plugin. Activate the plugin and watch it run with the rest of the plugins. If you insist on putting the `add_action` in the theme's `functions.php` then simply define a constant in your point of entry script, like this: `define('SCRIPTONOMY', true);` Finally run a conditional in the `functions.php` testing for the constant.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "loop, plugin contact form 7, outside wordpress" }
WooCommerce - Where is functions.php? I have a very simple question (I hope). I am trying to edit the number of products displayed on my Shop page in my WooCommerce WordPress site, and all attempts thus far have been unsuccessful. I have come across some documentation stating that you can put `dd_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );` in the `functions.php` file but I am unable to find the PHP file. I have searched all through the `root WP` folder, `/wp-content/plugins/woocommerce` folder, `/wp-content/plugins/woocommerce/includes` folder and `/wp-content/plugins/woocommerce/templates/` folder through an FTP client and haven't found anything. Where is it?
Woocommerce is a plugin. The `functions.php` file is a Theme component, which is auto-loaded by WordPress Core when the theme boots. While Woocommerce, or any other plugin, may have a file named `functions.php` but such is not required and it is not the `functions.php` typically referenced here and elsewhere when people suggest adding code that file, and a file of that name used by a plugin won't be auto-loaded by Core but would have to be loaded by plugin code. There are Woocommerce themes, which probably have a `functions.php`, though `functions.php` is not a required theme file.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, woocommerce offtopic" }
add_external_rule - rules deleted when visiting permalinks page In my plugin, I have the following function hooked to `register_activation_hook`. The rules are added correctly. public function add_rules(){ global $wp_rewrite; $wp_rewrite->add_external_rule( '(.+)\.([0-9\.\-\_]+)\.(js|css)$' , '$1.$3'); $wp_rewrite->flush_rules(); update_option($this->key.'-plugin-version', $this->version); } When I visit the Permalink settings page, the rule is deleted again. It is not added back when saving the Permalink settings. This is due to the way in which the Permalink page flushes all rules when it is opened. (Not when the settings are saved.) Is there a way to stop the custom rules from being deleted?
Leave your activation function as it is, and create another for the rewrite rules hook: function wpse_209303_rewrite_rules( $wp_rewrite ) { $wp_rewrite->add_external_rule( '(.+)\.([0-9\.\-\_]+)\.(js|css)$' , '$1.$3'); } add_action( 'generate_rewrite_rules', 'wpse_209303_rewrite_rules' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, permalinks, rewrite rules" }
How to host unrelated pages on WordPress domain Is it possible to have separate pages hosted on a WordPress site? For example, say I have my site `www.website.co.uk`, which has my WordPress blog and all that. Obviously it'll have things like `www.website.co.uk/blog/`. What I want is to have something like `www.website.co.uk/~pages/unrelatedthing` where it would read the `.css` and `.js` files in that folder and just load them. So I could have `www.website.co.uk/~pages/unrelatedthing/index.html`. No WordPress or anything. Basically I have a couple websites, and I don't want to pay for hosting for the lot of them but still want them accessible, so want to shove them under my still-hosted website.
Sure. Just add the subdirectory and then in your `.htaccess` file (in the base directory) add, before the index.php redirect lines another redirect something like <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^/otherdirectory/(.*) [L] </IfModule> Just make sure you dont have any url's using `otherdirectory` in your wordpress installation.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, htaccess, directory" }
Get WP Navigation Menu from REST API V2 I'm trying to get the navigation menu from JSON response using WP REST API v2 plugin. _There is no navigation menu plugin extension for the REST API **v2** , but only for V1._ From codex WordPress Post Types, I learned that the navigation menu is treated as a post type. From Rest API Doc, this is how we get posts of a type: `GET I tried to get it like so: `URL : I received 403 error. `{"code":"rest_cannot_read_type","message":"Cannot view type.","data":{"status":403}}` the server understood my request but it refused to give the data. **Q: How can I fix this?**
There is a navigation menu plugin extension for the REST API v2: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 24, "tags": "menus, json, plugin json api, wp api" }
Using W3 Total Cache, I set expire headers to media, css and js files,but it seems doesn't work I used W3 total cache to improve the site performance. The problem is I've set expire headers to my media,css and js files, but when I run test in page insight and gtmetrix,the report indicate I did't set expire header to the files. I've checked the .htaccess file, there are rules in it. What do you guys think the problem? Thanks!
My first port of call would be to make sure that you have all the appropriate modules enabled for your server. For example, on a LAMP stack: In your apache's http.conf the following lines would need to be uncommented LoadModule expires_module modules/mod_expires.so LoadModule headers_module modules/mod_headers.so LoadModule mime_module modules/mod_mime.so You would need to restart your apache server for this to take effect
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Display success message after wp_update_post I want to display a success message on updating a form from front-end using `wp_update_post` at the top of the form. I use below on edit page $post_id = wp_update_post($edit_post); and defined function function write_here_show_success_messages( $success_msg ) { echo '<div class="form-success">'; echo '<span>'.$success_msg.'</span><br/>'; echo '</div>'; } How do I execute this function when the form is updated at the top of the form(or specific location on the page)?
wp_update_post > The ID of the post if the post is successfully updated in the database. Otherwise returns 0. So just test again that. if ( $post_id != 0 ) { // success! write_here_show_success_messages(); } Or you can use an action. <?php /** use action for success message **/ if ( $post_id != 0 ) { // success! add_action('form_message', 'write_here_show_success_messages' ); } ?> <div> <?php do_action('form_message'); ?> <form> <!-- form contents --> </form> </div>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, wp update post" }
How can I choose and change a post title at random from an array when it is published? I want to populate an array with post titles and change the title of the post (which is a draft) to a random member of the array of titles. Something like this? function set_random_title ($title) { $title1[0] = "a title"; $title1[1] = "another title"; /*and so on*/ $randomize = rand(0,1); return ($title1[$randomize]); } add_filter('the_title', 'set_random_title', 10, 2);
You could randomize the array with array_rand which will return the key, and then use array_flip to switch the key with the value (ie get your random title). Hook into save_post, so the random title is assigned and update the DB when you actually publish a post as opposed to using the_title filter. function save_title( $post_id ){ global $wpdb; $title = array ( '1' => 'another title', '2' => 'here is again, a title', '3' => 'random titles', '4' => 'RANDOM TITLE', '5' => 'ANOTHER RanDom TiTlE!', '6' => 'titles everywhere' ); $wpdb->update( $wpdb->posts, array( 'post_title' => array_rand( array_flip( $title ) ) ), array( 'ID' => $post_id ) ); } add_action( 'save_post', 'save_title');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, title" }
Plugin to show how far users are reading? I have plugins to count users per post per day, but i don't have any idea how far the users are actually reading. Are there any plugins that can show that?
If you have Google Analytics available, you can try out the WP Scroll Depth plugin
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "statistics" }
How to reset display of WYSIWYG editor I recently installed WordPress on a new domain but I have a small problem. This WYSIWYG editor displays very small text with no padding. Here are some examples. **Desired behavior:** ![desired behavior]( **Actual behavior:** ![actual behavior]( As you can see, the second image shows text which is considerably small and hard to read. It also has no padding so it runs right into the sides of the text editor. How can I reset the display? I'm running WordPress 4.3.1 with the Gravit theme. No plugins are active. I installed it yesterday.
Looks like the Theme you are using adds style to the editor using `add_editor_style()`. Check for that code in theme files and just comment it out by adding a `//` so that it looks like `//add_editor_style( ... );`. Alternatively, you can look for a file named `editor-style.css` in theme's root directory and rename it to something else. **EDIT:** Yes, it does add editor style. You can comment out the line# 326 in functions.php to use the default WordPress styles for Editor. //add_action( 'init', 'gravit_add_editor_styles' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "visual editor, wysiwyg" }
How will php 7 affect Wordpress? Will the new php 7 version be backwards compatible or will we face compatibility issues? Will it greatly affect the way we code for WordPress? My host offers php 7, should I use it for a WordPress site now?
WordPress has been preparing for PHP 7 for a while and, according with this announcement, WordPress should support PHP 7 since November 12th. According with the same announcement WordPress will still supoort PHP 5.2.4 as minimun requeriment, although it is recommended at least PHP 5.6. The downside: there are propabably so many plugins and themes that are not compatible with PHP 7 that using PHP 7 or not right now can not be a general recommendation. If you use third party plugins you will have to test your sites one by one and ask to the support team of those plugins if they plan to support PHP 7.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "php" }
How to enable comments meta box for other author posts? I am working with a ticket system which is a custom post type. Tickets can be created on the front end of the site. Registered users can post a new ticket, which can be moderated by administrator and needs to add a comment after approving it. WordPress is not allowing other authors' posts to have new comments added by default. I mean, it only allow us to post a new comment, if we are the author of the post. Is there any action, hook, or function that would allow administrators to add a new comment to any author's posts from the back end, while moderating the post.
Thanks for all of your answers guys. Finally I found solution for me issue. Once the post is published we can add comments. If the post is pending it won't allow administrators to add a new comment. The answer is simple, if we publish the post we can add comments.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, comments, wp admin" }
<a> with PHP within splits the link I've finally found out how to call a the project-type in a link so the link changes depending on which page it shows. This is the code: <h3 class="widget-title"> <a href="../">Terug naar <?php the_terms($post->ID, 'fluxus-project-type'); ?></a></h3> But what happens now is the following. Both 'Terug naar' and the result from ID, 'fluxus-project-type'); ?> get split. Example is found on the left side of the page at: < Terug naar and Schilderijen are split in 2. How can I combine those so it's one link? Thanks in advance!
What you are doing isn't ever going to work the way you want. `the_terms()` is going to produce a list of complete `a` tags so you can't nest or merge it with another one like you are trying to do. And there are no convenient arguments or filters that would allow you to alter that link text. There are some not-so-convenient ones though. The simplest is a filter on `get_the_terms` function prefix_term_name($terms, $post_id, $taxonomy ) { foreach ($terms as &$term) { $term->name = 'Terug naar '.$term->name; } return $terms; } Which you would use like: ?> <h3 class="widget-title"><?php add_filter( 'get_the_terms','prefix_term_name',10,3); the_terms($post->ID, 'fluxus-project-type'); remove_filter( 'get_the_terms','prefix_term_name',10,3); ?> </h3><?php The function definition itself can be in your `functions.php` file to keep things neat. }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, links, split" }
I want to show my post for limited time, how is it possible? I want to make one website like a newspaper, so i want to show my daily post for one day or limited time, after one day previous post will go to archive and no longer show on web page, how is it possible?
You should use `cron job`. Yes WordPress has a function `wp_schedule_event ()`. This function will perform certain operations based on the time difference you add it. Say for example, if you schedule it `daily` this will works everyday and perform the operarions on daily basis. you can hook a function with `wp_schedule_event`. Just get the published posts list and from the posts check the date of publish and current time. If it marches today leave it. Otherwise you can edit the post and change the status as draft or you can even delete it. Here I didn't give you code samples. If you require there are many question available about cron job and post status change. Just Go through it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, archives, limit" }
Get the correct post id for all post and page in header.php I want to get the current post/page id outside the loop (in header.php) and use this id for Advanced Custom Fields plugin to get the fields. But i cant get the correct id from front page, archive page(tag, author, category...etc). Here is the code if ( is_singular( 'post' ) ) { $post_id = $wp_query->post->ID; echo 'post id' . $post_id; } elseif ( is_shop() ) { $post_id = get_option( 'woocommerce_shop_page_id' ); echo 'post id' . $post_id; } else { $post_id = get_queried_object_id(); echo 'post id' . $post_id } One more question, any better method to get the id for all of the page outside loop? I just worry my code is still miss some of the page type.
`get_queried_object_id()` will return the ID of the current single post or page being viewed, as well as the static front page. For any type of archive page ( _except date, custom post type and home archives_ ), the following will be returned: * Category ID of the category archive being viewed * Tag ID of the current tag archive being viewed * Author ID of the current author archive being viewed * Term ID for the current term page being viewed If this is not the case in your case, you, your theme or a plugin you are using is in all probability using `query_posts` somewhere. `query_posts` breaks the main query object and resets the main query object to the custom query using `query_posts`. This is why you should **never ever** ue `query_posts`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "id" }
How do I make images open in a new tab by default? When I insert a large image into a post, I would like the image to open in a new browser tab rather than within the existing tab. I know that this can be accomplished by adding `target="_blank"` to the link, but how do I add this attribute to the image links?
## If you cannot write codes: There is a Plugin MDC Target Blank, that'll solve the issue. When someone clicks on a link (or an image that is hyperlinked), it'll force to open in a new tab. It adds `target="_blank"` to `a` tags. Older versions of this plugin had a bug, that's fixed in new versions. So, don't worry about the plugin ratings. ## If you can write codes: Add this code to your theme's `functions.php` file function mdc_target_blank($content) { $post_string = $content; $post_string = str_replace('<a', '<a target="_blank"', $post_string); return $post_string; } add_filter( 'the_content', 'mdc_target_blank' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "urls" }
What's the Max character limit for a post in WordPress? Very software out there has a limit for character but I haven't seen any such limit for a post in WordPress. So I need to know if there is actually a Max character limit for a post in WordPress or not? If there is then what's the limit?
If you check the database description you'll see that the post content column is `longtext`, which is: > A TEXT column with a maximum length of 4,294,967,295 or 4GB (232 − 1) characters. The effective maximum length is less if the value contains multibyte characters. The effective maximum length of LONGTEXT columns also depends on the configured maximum packet size in the client/server protocol and available memory. Each LONGTEXT value is stored using a 4-byte length prefix that indicates the number of bytes in the value. > > < You will more likely run out of usable memory before the max character length becomes an issue.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "characters" }
Count of posts by different parameters? I need to get the count of posts (just a number, nothing else) by `custom taxonomy` AND `post meta(string)` but I can't find a good way to combine them both. Im fairly new to programming & WP, Im not sure where to start from.
Use `WP_Query` with a `tax_query` and a `meta_query` argument, and return only IDs to save a bit of server resource. $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob', ), ), 'meta_query' => array( array( 'key' => 'age', 'value' => array( 3, 4 ), 'compare' => 'IN', ), ), 'fields' => 'ids'. ); $query = new WP_Query( $args ); And check the `found_posts` element of `$query`\-- `var_dump($query->found_posts);`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, post meta" }
Replace Gravatar with uploaded images? I've added functionality to upload profile picture by following THIS guide. I can't find an online guide or any documentation about WP hooks.. **How to replace Gravatar profile pictures (in comment section) with custom uploaded images?** I don't want to force my users to register Gravatar in order to change their profile picture on my site.
If you are set your custom or uploaded profile picture and need to see on front end, you can use below function . <?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?> If you have to change your gravatar to custom profile picture you can refer below link : <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 5, "tags": "profiles, gravatar" }
Two types of layout in woocommerce SHOP page In my project I want to show product list in two ways on single page. 1. First in gallery way in which 4 products in one row.(This I have already created). 2. And second in list way(one product at a row) which I will create. But I actually what I want is that to provide an option to customers whether he/she want the products view in gallery form or in list. Two button(gallery and list) will be provide to them. BY clicking on gallery the view should be like gallery and vice versa.Any idea, how it can be done. NOTE: Ok, If anyone likes to give negative rating to any question then please also make some effort to explain the reason in the comment section, this won't take long. That will help us to find batter way of asking question.So don't reside your thoughts in your head, Share with everyone, that will be helpful. No Offence !
Set a button, or dropdown menu, that calls a function to set a cookie and to switch between CSS files which contain the `_style` ID: function switchStyle(style) { var file = $TMPL_URL + '/css/' + style; jQuery('head').append('<link rel="stylesheet" href="' + file + '" type="text/css" />'); jQuery.cookie($TMPL_NAME + '_style', style, { expires: 365, path: '/' }); } `jQuery.cookie` should be replaced with whatever your standard cookie function is. Change `expires: 365` to set whatever duration you wish, so the page remembers which setting was chosen for that user.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -2, "tags": "themes" }
Conditional pagination li's I've noticed that must paginations in Wordpress are constructed like this: <nav class="post-nav clear clearfix"> <ul> <li class="previous"><?php echo get_next_posts_link( 'Previous', $the_query->max_num_pages ); ?></li> <li class="next"><?php echo get_previous_posts_link( 'Next' ); ?></li> </ul> </nav> No matter if there's a previous or next link, the li's always show. Is there a way to wrap this li's around a conditional to only show if "Previous" or "Next" posts exists?
Yes, but it is really more PHP than WordPress. You just need to reorder things and add some logic: $next = get_next_posts_link( 'Previous', $the_query->max_num_pages ); $previous = get_previous_posts_link( 'Next' ); if(!empty($next)) { $links[] = '<li class="next">'.$next.'</li>'; } if(!empty($previous)) { $links[] = '<li class="previous">'.$previous.'</li>'; } if (!empty($links)) { ?> <nav class="post-nav clear clearfix"> <ul><?php echo implode($links); ?> </ul> </nav><?php }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pagination" }
Get Posts Based on Tag Matching Page Title I have the following written to retrieve a list of posts that match the title of the page, by their tag. The problem is it does not play nicely with tags that have multiple words (and perhaps special characters too but I have yet to run into that). <?php $title_post_tag = new WP_Query( array( 'tag' => strtolower( get_the_title() ) ) ); while ( $title_post_tag->have_posts() ) : $title_post_tag->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php the_date(); ?></p> <?php endwhile; ?> I have read up on needing to sanitize in php but I'm not entirely sure how to use that in this context or if it would even help me at all. Guidance is greatly appreciated.
I overlooked `get_queried_object()->post_name` Under: $title_post_tag = new WP_Query( array( 'tag' => strtolower( get_the_title() ) I changed it to: 'tag' => get_queried_object()->post_name So far, it looks like it is working.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, page template" }
Always paste as a text in visual editor I am running a multi author blog. I allowed only visual editor for authors. So, i don't want to allow them to paste disallowed html tags from other source. I want, text will always paste as **plain text**. Please help !
function tinymce_paste_as_text( $init ) { $init['paste_as_text'] = true; return $init; } add_filter('tiny_mce_before_init', 'tinymce_paste_as_text'); For details please follow link : tiny_mce_before_init Thanks!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "editor" }
Adding wrapper elements in the_date() like in the_title()? So this works: the_title( '<h1 class="entry-title">', '</h1>' ); But this does not: the_date( '<h4 class="entry-date">', '</h4>' ); I don't know enough if this is reserved for `the_title()` or if the twentyfifteen theme has specified this functionality in functions. I don't see it but I could be missing it. Or course, just printing `the_date();` works as it's supposed to as well as pulling it out of the php block and wrapping it in html myself also works. Just thought there could be a nifty little way to do it like `the_title` there.
The Codex ( or Developer Resources ) is a fantastic tool when you're unsure about a function. Looking at the parameter list for `the_date()` it says: the_date( $format, $before, $after, $echo ); So you need to pass in a format as the first parameter, then your HTML tags like you have it. An example could look like this: the_date( 'l, F j, Y', '<h4 class="entry-date">', '</h4>' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, functions, templates, page template" }
How to add HTML5 required on wp_editor I want to add HTML5 required for the client side validation on textarea generated by <?php $content = ''; $editor_id = 'YOURID'; wp_editor( $content, $editor_id ); ?> What is the best way to add `required` on textarea? Thank you.
The visual editor is not a textarea, it is an iframe, therefor even if you could set an attribute it will do nothing. You can set the attribute on the hidden textarea that will be sent to the server but since it is hidden I am not sure how an alert about it not being filled will be displayed and it might be different between browsers (it is hidden so there is no obvious visual anchor for the display of the alert)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, editor, wp editor, validation" }
Too many wp-cron requests even when disabled We have a webserver with a number of WordPress instances. Most, if not all of them have disabled `wp-cron.php` using the `wp-config.php` line: define('DISABLE_WP_CRON',true); Despite this, there are more than a thousand requests a day that are made using wp-cron, and a typical logged request looks like this: example.com:80 my.ip.add.res - - [19/Nov/2015:10:38:10 +0000] "POST /wp-cron.php?doing_wp_cron=1447929490.3804519176483154296875 HTTP/1.0" 404 36435 "-" "WordPress/3.9.6; It's a 404 request, because after trying really hard, I have deleted `wp-cron.php` from the folders. I know this is more of a server management question, but where does WordPress originate the wp-cron request from? Is there any part of the code that I could modify to ensure that this is never called? Just felt it may help to add the entire config file (barring credentials) here <
The cause is that the define in wp-config.php is below the line saying `/* That's all, stop editing! Happy blogging. */` Anything defined below that is unlikely to have any impact on how wordpress works.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "wp cron" }
using `require` in my functions.php breaks the site So, I have a snippet of code I'd like to tidy away in a directory that's close to the root my wordpress directory. Specifially it lives in /includes/inc. I've created a file called test.php and within it it simply says echo "XXXX"; All I currenly want to be able to do is include this file in my functions.php file and see the sting printed to the screen. The issue I'm seeing is that no matter what path I put into require, the page break. Even no path at all breaks the page. I'm 100% sure this is the correct path as well. Why might this be happening? Inside the functions.php file at the very top, below comments. require('/inc/test.php'); Inside the test.php file inside /inc within the theme folder: echo "TEST XXXXXX"; I've tried using * require_once * require * include (just does nothing) * include_once (same as include - does nothing)
Try require('inc/test.php'); instead of require('/inc/test.php'); Remove / before inc.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, include" }
Passing attributes to shortcode dynamically Can I pass dynamically to shortcode attributes like as the following example shows [ authoorsposts author = get_the_author_id(); ]
Not quite like that, but you can achieve the same result if you use a pre-defined value or argument in your shortcode to act as a "flag": [authoorsposts author="post"] ...then in your handler: function wpse_209684_author( $atts ) { if ( ! empty( $atts['author'] ) ) { $author = $atts['author']; if ( $author === 'post' ) // Our flag, make $author the current post author $author = get_the_author_id(); else // Otherwise just accept a hardcoded author ID $author = absint( $author ); } }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "shortcode, variables" }
WordPress /page/2 404 pagination problem - what to do? I came across the `/page/2` 404 pagination problem and tried to find a solution. I've read some suggestions, but it didn't help yet. Working: < Not working: < I've been trying to figure this out for hours. I understand WordPress assumes "page" is a post from the category "bolos, doces e sobremesas" since my permalink structure is `/%category%/%postname%/` but I don't know how to fix it.
Found the solution! Installing this plugin solved the problem: < I also had to make changes in Settings > Reading to show less than 10 posts per page (I'm showing 6 posts per page now, but anything below 10 should work). Hope it works for you all. :)
stackexchange-wordpress
{ "answer_score": -3, "question_score": 22, "tags": "pagination, 404 error" }
How to add bubble count in WordPress wp_nav_menu menu? I have to add a bubble notification in WordPress `wp_nav_menu` like the following code. <ul> <li> Tickets <span class="unread">2</span></li> <li> Log-out</li> </ul> Here I have to add this part in it. <span class="unread">2</span> I have seen this one and tried it. add_action( 'walker_nav_menu_start_el', 'wpse_10042_nav_menu_post_count', 10, 4 ); function wpse_10042_nav_menu_post_count( $output, $item, $depth, $args ) { $output .= '<span class="unread">'.my_function_here().'</span>'; return $output; } And get it from here How to add post count to wp_nav_menu? But the problem is its adding to every menu link. I want to add it to only one menu item. Not everyone in the list.
For flexibility, you could assign the CSS _bubblecount_ class to the corresponding menu item: ![enter image description here]( and then target it with: if( in_array( 'bubblecount', (array) $item->classes ) ) $output .= '<span class="unread">'.my_function_here().'</span>'; in your code snippet above.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "menus, comments" }
Pass Shortcode Attribute to footer Script I am trying to generate a WordPress shortcode which will display a bxSlider. The shortcode function itself works like a charm; I can pass my data and the shortcode is rendered properly. **The problem:** In the shortcode I also added an attribute `id`, which will be used to pass an ID used to call the slider, so for example: $(".myid").bxSlider({ So the `"myid"` part would be passed like `[myshortcode id="myid"]`. But as the script needs to be placed in the footer (using: `add_action( 'wp_footer', 'myshortcode_function');`). So, I have to call the `id` attribute outside the shortcode function. Could anybody please explain, how to pass that attribute so I can use it in another function? Please do not link me to the documentation. I read it, and I don't understand it.
It's simple. WordPress have a handy function to send variables to a registered script. It's `wp_localize_script`. It work this way: //First Register Your Script wp_register_script( 'name-of-script', ' '', '', true ); //Then send dynamic variables wp_localize_script( 'name-of-script', 'globalVar', array( 'id' => 'slideTarget' ) ); //Finally invoke it on Front-End wp_enqueue_script ( 'name-of-script' ); This should outputted before the script is called, and since it's called on footer, you can just call it inside your shortcode function. Then, on your script, you will need to use it like this: $("#" + globalVar.id ).bxSlider({ Simple as that. There are other options as well, like outputting a global var or outputting a hidden input with the target ID, so you script would just need to looking for that hidden input value.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions, shortcode, customization" }
How do I exclude all images from a wp_query? I want to query attachments and exclude all images. I can see how to include _only_ images, using `'post_mime_type' => 'image/*'`, but I couldn't find any way of achieving the opposite. Is there any mime_type equivalent of `posts__not_in`?
Pretty much the solution is to include all mimes _except_ images. WordPress has a nifty little function where it keeps all it's accepted mime-types called `get_allowed_mime_types()` ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we don't want in our query: $unsupported_mimes = array( 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon' ); $all_mimes = get_allowed_mime_types(); $accepted_mimes = array_diff( $all_mimes, $unsupported_mimes ); $attachment_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => $accepted_mimes, 'posts_per_page' => 20, ) );
stackexchange-wordpress
{ "answer_score": 12, "question_score": 4, "tags": "wp query, images, attachments" }