INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
the_post_thumbnail(); only works with fullsize images The author of the theme, im using, used "the_post_thumbnail(array(120,120));" to define the thumbnail size. but for some reason, it only works with small banners (300x84), but i need those banners to be bigger in height. And than, the theme uses the full size picture in a thumbnail area of (68x165) And if i use smaller banners, the pixels would be visible. This is my first WP project and im not familiar where all the stuff is, that i need to fix this problem. also: no plugins installed. (except 'regenerate-thumbnails', but i installed it, to see, if it can fix that problem. Didn't work, otherwise i woudn't waste your time with that question.)-> Some other posts wrote, that this plugin could solve this problem. But not in my case.
You have to tell WP to generate this image sizes at first... Use function `add_image_size` and then "regenerate the thumbnails": add_image_size( 'custom-size', 220, 180, true ); // 220 pixels wide by 180 pixels tall, hard crop mode Note "custom-size" string which could be anything you want. < After that you can use the `the_post_thumbnail` function with our custom defined image size "custom-size": the_post_thumbnail( 'custom-size' ); < More resources: * < * < * <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php" }
Change post-slug using wordpress API? Change permalink of a post using php / jquery? When calling `wp_insert_post()` see api there seems to be no possibility to set the post slug / the post permalink of the new entry. e.g. is there a way to check if: a string is possible to use as post-slug, if not available return error.
`post_name` is the slug. 'post_name' => [ <string> ] // The name (slug) for your post You'll need to query for a post with matching slug before inserting a new post, WordPress will just append a number to make it unique if there is a duplicate.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, wp admin, api" }
Two live WP websites - how to sync? I need to have two websites in different servers, because of really slow page load times from China. So we are planning to take server from China and clone/sync website. I'm not familiar of syncing live websites. What kind of solutions is available for this? What are the drawbacks and problems on this? What must be taken into account?
You have basically tree ways. 1. WP API (JSON) 2. Feed (XML) 3. XMLRPC API I think the first solution via WP JSON API should be your prioritized way. The WP API will implement inside the core of WordPress in the next releases. Currently you can use it via plugin. I think, this is the standard for the next time for work with data from the WP install. Also you find a lot of tutorials, examples to use the data. For the authentification use OAuth, like this plugin. You find much more hints, tutorials in the documentation about the API. Also interest is the actually hint from the developer side.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "server, sync" }
Woocommerce Variable Product - Please choose product options… Running my own designed custom theme "mdbootstrap" designed by myself. Integrating WooCommerce 2.4.12. and upon testing there is an issue adding variable products to the cart. Basically the add to cart button is hidden and doesn't appear once a variant is selected . If I switch to the TwentyEleven theme, the issue resolves itself. I can force button to show by adding to css .single_variation_wrap{display:block !important;} but even then when I submit "Add to card" page is reloading and when I move to cart page I am getting error: Please choose product options… Variable product: < Normal products works like a charm: < You have to be logged in: username: test password: test
I'm not sure why but you have form tag inside a form tag.. and chrome is making it as one... view source and look for `<form class="cart" method="post" enctype='multipart/form-data'>` and `<form class="variations_form cart" method="post"` `<form class="variations_form cart" method="post"` was removed by the browser which is the one needed by woocommerce.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "woocommerce offtopic" }
Customizing WooCommerce I'd like to customize something in woocommerce. Here is the example: I've added some categories in woocommerce (Product Categories). For example, there are two categories like "SALE" & "New Arrivals" Now I want to put 2 drop downs in just one category for example I want all the products in "SALE" category to have 2 drop downs on each individual single product page. There will be two drop downs like "Choose a color" & "Choose a fragrance". This also needs to be integrated with the backend order dashboard so that each of that order shows the admin with the desired color and fragrance. Please suggest since I'm not sure what to do. Thank you!
What you are looking is variable product. You can create variation "Color" & "Fragrance". in variable products When you are creating a product in backend you can select a product type as variable and add variations. You can see an example below ![example](
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "woocommerce offtopic" }
Using Travis CI to run unit tests and running phpunit locally Is there a difference between Travis CI running my PHPUnit tests and me using the WP-CLI to generate unit test files and running `phpunit` locally? I'm wondering if the duplicate effort is necessary or unnecessary.
Travis is a hosted continuous integration service. Travis takes the files you've committed to your Github repo, and runs PHPUnit against them. Notably different than running `phpunit` in your local environment is that running tests on Travis requires at least three steps: 1. Commit to Git. 2. Push to Github. 3. Wait for Travis to create and run a build. In the long term, it will be much faster for you to first run your tests locally before you commit, to reduce the amount of time you have to wait to see if your tests fail.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "wp cli, unit tests" }
How to use the new Wordpress 4.4 JSON API? Until today I have used the plugin "WP REST API (WP API)". Now I want to use the built-in API but can't find any documentation on it. Any idea?
The WP REST API is being developed for WordPress as a **Feature Plugin**. A **Feature Plugin** is: > ... the way for features to be developed for inclusion in WordPress core. This model allows a feature to be built, tested, refined, and polished before it is considered as a merge candidate _source_ : < Therefore, the WP REST API _is_ the new WordPress built-in API and the documentation for the WP REST API plugin is also the documentation for the built-in WP API. However, **not all features from the plugin have been merged into core WordPress yet**. For WordPress 4.4, the best documentation of how to use what is **currently built-in** into WordPress is documented in this post on the Make WordPress blog: > **REST API: Welcome the Infrastructure to Core** < However, because the merge into WordPress core will be an on-going, phased process, the best way to keep up with changes per release is to track these sources: * Make WordPress 'rest-api' tag: < * Github: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "json" }
Remove WordPress Login Animation So with WordPress if you fail a Login the screen refreshes and when it does the Login Form does this shake animation which I don't really like I was wondering if there is a way to get rid of this? I'm grateful for any help :)
This will remove the shake -- at least that's what Google says. function wpb_remove_loginshake() { remove_action('login_head', 'wp_shake_js', 12); } add_action('login_head', 'wpb_remove_loginshake');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "login" }
How to add placeholder for contact form7 for dropdown? I tried adding placeholder similar to the given for **ContactNumber** for my drop down **Outlet** but it doesn't appear. Code- <div class="form-group form-icon-group"> <i class="fa fa-phone" > </i> [tel* ContactNumber /8 class:form-control placeholder "Contact Number *"] </div> <div class="form-group form-icon-group"> <i class="fa fa-food" > </i> [select Outlet id:outlet class:form-control "-- Select Outlet--" "Pasir Ris" "Thomson"] </div> Tried adding `first_as_label "Preferred outlet?"` so this displays as ordinary drop down values. Rest all of the fields do show the placeholder,any other way to give placeholder for drop down?
to answer the question: this is not possible. AFAIK, (HTMLwise) there's no way to add a placeholder to select tags. A lot of devs I know however tend to use `disabled selected` combination for the option... <select> <option value="" disabled selected>Select your option</option> <option value="ydasdas">ydasdas</option> <option value="dasda">dasda</option> <option value="ydagfdsdas">ydagfdsdas</option> <option value="ewefsdf">ewefsdf</option> </select> demo I have checked CF7's source code (version 4.3.1), and there's no easy way we can achieve this html format. You can go the hard way by removing `wpcf7_add_shortcode_select` action on `wpcf7_init` and add yours instead.
stackexchange-wordpress
{ "answer_score": -2, "question_score": 24, "tags": "plugin contact form 7" }
Wrap post thumbnail with <figure> I'd like to wrap my post thumbnail with `<figure>` tags. I have tried the following and the image appears, but the `<figure>` tags come up empty. <?php if ( has_post_thumbnail() ) { echo '<figure>'.the_post_thumbnail('gallery').'</figure>'; } ?> I've also tried the following, but the image is missing and only the empty `<figure>` tags appear. <?php if ( has_post_thumbnail() ) { echo '<figure>'.get_the_post_thumbnail('gallery').'</figure>'; } ?> **UPDATE** For anyone wanting the full code from the answer, here it is: <?php if ( has_post_thumbnail() ) { echo '<figure>'.get_the_post_thumbnail( $page->ID, 'gallery').'</figure>'; } ?>
Use get_the_post_thumbnail( $id, $size ) if you're going to echo the result. And make sure you have post thumbs enabled. add_theme_support( 'post-thumbnails' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "post thumbnails" }
Redux Framework has an embedded demo. Click here to activate the sample config file I developed the theme. Redux Framework configuration file located in the theme directory. Himself ReduX Framework I installed from the repository Wordpress using the TGM. But when I install a theme, then this message appears > Redux Framework has an embedded demo. Click here to activate the sample config file. and I need to click on the link for load my options! How can I make so that my settings are automatically loaded? functions.php in my theme /** * Redux */ if ( class_exists( 'ReduxFramework' ) ) { require_once( dirname( __FILE__ ) . '/inc/options-init.php' ); }
Problem solved! Helped official support. It was necessary to add the following code. add_action( 'redux/loaded', 'remove_demo' ); /** * Removes the demo link and the notice of integrated demo from the redux-framework plugin */ if ( ! function_exists( 'remove_demo' ) ) { function remove_demo() { // Used to hide the demo mode link from the plugin page. Only used when Redux is a plugin. if ( class_exists( 'ReduxFrameworkPlugin' ) ) { remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::instance(), 'plugin_metalinks' ), null, 2 ); // Used to hide the activation notice informing users of the demo panel. Only used when Redux is a plugin. remove_action( 'admin_notices', array( ReduxFrameworkPlugin::instance(), 'admin_notices' ) ); } } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, theme development, theme options" }
Separating a custom taxonomy from blog post-type Whenever I invoke `register_taxonomy` in my site's custom plugin, all taxonomies are created as children of the blog post-type in WordPress by default. I just want them to be top-level items in WordPress, not children of the default `blog` post-type. I reviewed the `register_taxonomy` array parameters extensively and don't see a way to do this. Using Admin Menu Editor, it's pretty simple to move custom taxonomies into their own admin menu. But at the system level, is their some hook to make a custom taxonomy its own entity inside of WordPress? Using breadcrumbs as a mental model, this is the way things currently are: * Home > Blog > Custom Tax I just want: * Home > Custom Tax
No. As far as the admin menu is concerned the taxonomies are always "below" the content they apply to. You will always need to directly manipulate the menu structure to change this.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "custom post types, custom taxonomy, admin menu, register taxonomy" }
Display Content Based on Custom Field Value I have the following code which is trying to show an image based on the value selected from a custom field in the admin screen. <?php if( get_field('bias') != 'Neutral' ) { ?> <img src=" /> <?php } elseif ( get_field('bias') != 'Bullish' ){ ?> <img src=" /> <?php } elseif ( get_field('bias') != 'Bearish' ){ ?> <img src=" /> <?php } else { ?> <?php } ?> The above only kind of works. It shows the bear image for the neutral value and the neutral image for the bullish and bearish values. I really don't need the 3 options. I think my code is just a little off somewhere. Can anyone help? P.S. I'm using Advanced Custom Fields.
You have a logical error. You check if the field is `!=` and not `==`. So if the field name is Neutral the first check will fail and it will go to the second one and it will succeed. You ask is Neutral not equal to Neutral and the answer is false because Neutral is equal to Neutral. The same for the other ones. <?php if( get_field('bias') == 'Neutral' ) { ?> <img src=" /> <?php } elseif ( get_field('bias') == 'Bullish' ){ ?> <img src=" /> <?php } elseif ( get_field('bias') == 'Bearish' ){ ?> <img src=" /> <?php } else { ?> <?php } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, custom field, meta value" }
Update user_login, user_nicename, and display_name I have about 600 user records I've imported from a WooCommerce site, but they have the email as their username and I need their username to be first.last So I'm trying to find a SQL way to update all user_login, user_nicename, and display_name fields in the wp_users table with the first_name and last_name information in the wp_usermeta table. * user_login should be in the format: first.last * user_nicename should be in the format: first-last * display_name should be in the format: First Last This should also only apply to users with the role of "Customer" ( `meta_key= wp_capabilities meta_value= a:1:{s:8:"customer";b:1;}` in the `wp_usermeta` table). I understand basic sql, but not when working with multiple tables. :(
You don't need SQL, and shouldn't use it when Core functions will do the job. Part of the reason why is the complexity of the tables (and the fact they might change). 1. Query your users, 2. loop through pulling metadata, 3. and update Proof of concept: $u = new WP_User_Query( array( 'role' => 'customer' ) ); foreach ($u->results as $user) { $fn = get_user_meta($user->ID,'first_name',true); $ln = get_user_meta($user->ID,'last_name',true); $user->data->user_login = strtolower("$fn,$ln"); $user->data->user_nicename = strtolower("$fn-$ln"); $user->data->display_name = "$fn $ln"; wp_update_user($user); } You really should create some logic to check that `$fn` and `$ln` are not empty and compensate if one or both are. 600 users should update very quickly
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "sql" }
How to rename the wp-config.php file once under version control? git clone git://develop.git.wordpress.org/ develop After cloning the core development repository with Git, considering the files and folders are under version control, how can the config files be renamed to `wp-config.php` and `wp-tests-config.php`? .git src/ tests/ tools/ ... wp-config-sample.php wp-tests-config-sample.php I'm aware I can do `git mv wp-config-sample.php wp-config.php` but now my working copy is different from the upstream repository. Ref: <
Do not rename or modify the sample files unless such modifications are intended for contribution - they are there for reference. The files `wp-config.php` and `wp-tests-config.php` are explicitly ignored by `.gitignore`. Simply create them as new files yourself (or, if you'd like to use the sample files verbatim create symlinks to the sample files) to avoid unnecessary disparity with upstream.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp config, git, version control" }
Reuse links in a post across different languages I have posts in two languages, managed by WPML. In one post, I share multiple links which are updated in a regular basis. Updating the same links for both languages is not an option (for now I only added this post in one language). Which is the best way to define links text and URL only once, and reuse them in both languages? I could code a shortcode and manage the links by code, but I would like to know if there is any plugin or other approach to accomplish this (I already did my research with no luck).
I found the solution by using this plugin: **Global Content Blocks** I defined the links in `Content Blocks`. Then, all languages have the same shortcode pointing to a block. So, I only need to update the `Content Block` and the update propagates to all languages.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "links, multi language, plugin wpml" }
get_pages gives wrong ID for blogpage I have a problem with get_pages. It displays the wrong ID for the blog page. I have tried this code. $pages = get_pages(array("echo" => 0)); foreach($pages as $page){ echo $page->ID; } But for the blog page it returns the wrong ID. It should be 1 (the blog page is automatically 1 if I understand it correctly) but instead it returns the ID of the actual page. I've also tried the is_page() function, but that doesn't seem to work on objects. Is there any way arround this issue?
No, the blog page is just a regular page, it has no special ID number and it can be anything. The only special thing about a blog page is that it was assigned to use as a "blog" page and you can check for its ID value in one of the options.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "id, pages" }
Permalinks: Page Not Found When I open the newly created page in WordPress I get `page not found` but when I reset the permalinks to none ` opens normally . Even with this permalink it works : `/index.php/%postname%/` But when I change it to only `/%postname%/` I get `page not found error` . Here is my `htaccess` file: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
Do you have mod_rewrite enabled? This sort of thing tends to happen when it's not. At which point, you only have access to ugly permalinks (?p=N) or "almost pretty" permalinks (/index.php/slug). The latter uses pathinfo to get you the page you're requesting instead. So I'd suggest double checking whether mod_rewrite is installed and enabled. If it turns out it isn't, enable it and restart Apache. Here's more on using permalinks from the WP codex.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "permalinks, url rewriting, htaccess, rewrite rules" }
How do I show the WP admin error page? I'm building a simple event calendar, and I want to show a WP error page, for example when users try to edit an event that does not exist, see the attached picture (which is when you try to edit a post that doesn't exist) What is the correct Wordpress way to do this? I tried throwing errors and trigger_error() as I thought WP might handle the latter, but this isn't how it works. Note: I'm not trying to add a notice to my page, I want to show the WP error page. ![enter image description here](
`wp_die()` See the codex for full usage details: < You can even include html in the message field if you want to.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "404 error, errors" }
Change Post Title Edit Box When editing a post, the title field displays the placeholder "Enter title here" (it's actually a label element that's made to look like a placeholder attribute, but whatever). I have a custom post type where I'm using the title for something specific and I want to make it clearer what it is. Is there any way to modify this field or the way it's outputted? I couldn't find any filter for this. I could hook after it with `edit_form_after_title`, but I want to modify the field itself. I could remove the title field and use my own, but I want it to have the appearance of WordPress's title field.
You can add following code to your `functions.php` in the Theme-folder. Change the `Custom Post Type`(movie) name and the `title` to your wishes. function wpse213979_new_title_text( $title, $post ){ if ( 'movie' == $post->post_type ) { // Movie is the cpt name $title = 'Enter movie name'; // The text you want to be shown } return $title; } add_filter( 'enter_title_here', 'wpse213979_new_title_text', 10, 2 ); > The code reference Hope this is what you where looking for.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "custom post types, posts, metabox" }
What is a valid parent for get_terms()? get_terms($taxonomy, array('parent' => $parent)); This works for some parents and returns an empty array for others. I checked if a term with the parent ID exists and if the same ID is in the 'parent' field of the child term's taxonomy. Even copy-pasted directly from the database. Is there anything else? I don't see a difference between the parents that work and the ones that don't. edit: All invisible terms appear the moment I add a new term via the dashboard. Turns out the problem was that there is a function `wp_insert_term()` for adding terms and I was using `$wpdb->insert` and manually inserting the term and the taxonomy, which makes a difference, somehow.
Use `wp_insert_term()` instead of `$wpdb->insert` for adding new terms.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "php, mysql" }
Does a premium / for sale theme need to go through the Wordpress approval process? I am about to finish 2 themes for sale. Do I need to put these through the Wordpress.org approval process?
No, they don't need. They will need to go through the approval process of the marketplace where you will sell them (if any).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, premium" }
How to use sanitize_callback? Theme Check is telling me add_setting() should have a sanitize_callback function so I tried to add one. This is for a color selector: $wp_customize->add_setting($setting_name, array( 'default' => $default, 'transport' => $transport, 'sanitize_callback' => 'sanitize_hex_color', )); The error doesn't go away. Even if I make my own sanitize function, the error stays.
Turns out it was finding the error in some backup files I was keeping around. Once I removed those files, the error went away.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme customizer, sanitization" }
Use thumbnail image using url of that image I have the URL of my image and I want to display the thumbnail of that image. Is this possible. I check `the_post_thumbnail()` function but I can't add the URL of the image as an input.
Get the image ID from the URL with `attachment_url_to_postid()`: $image_id = attachment_url_to_postid( $image_url ); Convert the ID to the thumbnail image URL with `wp_get_attachment_image_src`: $thumbnail_url = wp_get_attachment_image_src( $image_id, 'thumbnail' );
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "post thumbnails" }
WooCommerce: Add Payment Gateway Field to Webhooks I have created a custom Payment Gateway for a special EFT system we have setup. The Bank Account and Routing Number are supposed to get encrypted then sent to a Salesforce via the WooCommerce webhooks to be processed. Unfortunately, I cannot figure out how to add the Bank Number and Routing Number as line-items to the Order Webhook. I have been able to add them to the product line of a webhook, but that is not helpful, because it makes the webhook messy when every product has the bank number and routing number in the array. I feel like I've tried about every hook and filter, and I've tried to look in the hooks and filters of some other payment gateways and i have not been able to figure it out. Any clues on how I can hook a field in a payment gateway to the Order webhooks?
Thanks, will do next time. I figured this one out: function my_custom_wc_api_order_response( $order_data, $order, $fields ) { $customer_info = get_post_meta( $order->id, '_customer_info', true ); $order_data['payment_details']['customer_info'] = $customer_info; // Apply filters if necessary if ( $fields ) { $order_data = WC()->api->WC_API_Customers->filter_response_fields( $order_data, $order, $fields ); } return $order_data; } add_filter( 'woocommerce_api_order_response', 'my_custom_wc_api_order_response', 10, 3 );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, filters, hooks, woocommerce offtopic, order" }
How to use json_decode a post_meta value? I have used `get_post_meta($post->ID)` to get all custom fields for my post since I have many of htem. Some of them were checkbox values and `var_dumping` the variable gives me this array (size=1) 0 => string 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";} How do I echo those values? I have tried `var_dump(json_decode($meta['my_var']));` but it gives me `null`
The values look like they have been serialized using `maybe_serialize( $data )`. If that's the case, then you can reverse that with `maybe_unserialize( $original )`. As per this answer, `unserialize( $str )` will also create a PHP value from a stored representation. * * * Try: $mydata = 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";}'; $mydata = unserialize($mydata); echo $mydata[0]; // ozujak
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "array, post meta, json" }
Polylang and United Arab Emirates languange I use Polylang Wordpress plugin and need to add United Arab Emirates language to site.. in drop down there is no options to chose corresponding language ( United Arab Emirates ) to Arabic.. but here < I can see 'ae' => __( 'United Arab Emirates', 'polylang' ), So, I try to add language with this settings: ( Locale: ar_AE, Code: ae ), but there is no flag ![ and also I get message to need download wordpress files because translate files is not downloaded Is there some options or alternative to get this work correctly.. maybe to add Arabic default language and just change custom flag, because its look like plugin not work with United Arab Emirates Localization
just to add comment for future if somebody have same problem.. polylang from version 1.8 will add options to add flag from plugin settings page, right now you can get this version from link < just download "Development Version (svn)" but only if stable version 1.8 its not released
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin polylang" }
How to make WordPress customizable for clients I was wondering how I can make WordPress customizable for clients? Such as, I use classes and ids in my span, paragraph, div, (etc.) elements... so how do I do this customization without having the client know about tags and classes? Thanks!
WordPress define the Customizer for doing this job. It works in frontend, on default, and you can enhance with your requirements. Also give it easier possibility to live preview of the options. You find a lot of how to here on WPSE and also in the wild of the www.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, widgets" }
Wordpress login screen not appearing after launch in microsoft azure I just launched a wordpress instance on azure but when I go to the URL, I get the following: > This web app has been successfully created > > There's nothing here yet, but Microsoft Azure makes it simple to publish content with GIT, FTP or your favorite development tool such as Visual Studio, Visual Studio Online or WebMatrix I tried < but no joy. I did this about a year previously and had no issues but not this time. Any ideas what I am doing wrong? Looking at: < I don't see any instance of MySQL in my window. I believe it is meant to start automatically. Any idea what I have done wrong?
In azure there is a bitnami wordpress instance. ![enter image description here]( I used the bitnami instance and the worpress login appeared as expected. I think you must launch a MySQL instance separately to use the wordpress but the bitnami instance works simply and is good enough for me.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "microsoft" }
can we add twitter count button on wordpress? i have seen many post regarding adding twitter's tweet button on wordpress page using different plugins. <script src=" type="text/javascript"></script> <a href=" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-via="wpbeginner" data-text="<?php the_title(); ?>" data-related="syedbalkhi:Founder of WPBeginner" data-count="vertical">Tweet</a> i want to ask that it is possible when someone click on Tweet button on wordpress site then after that tweet button should display number of tweets(every time increase the counter when someone clicks it)
It doesn't look like this is possible anymore (as of Nov 20, 2015) as Twitter's share count API has been deprecated. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "twitter" }
Select posts wich has no relationship in custom taxonomy I can select posts via my custom taxonomy as explained in the codex. But I am not sure, how I have to set up the tax_query if I want to get only posts which have no relation in the custom taxonomy at all. Any suggestion?
I have found an answer by myself, for those landing here by google: $taxq = array( array( 'taxonomy' => 'story_lng', 'field' => 'id', 'operator' => 'NOT EXISTS', ) ); That results in AND (NOT EXISTS( SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = 'story_lng' AND wp_term_relationships.object_id = wp_posts.ID)) AND wp_posts.post_type = 'story' AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') wich is basically the same as Pieter Goosen suggested, but merged in one query (and fewer lines of code).
stackexchange-wordpress
{ "answer_score": 8, "question_score": 1, "tags": "wp query, custom taxonomy" }
I am facing a problem with the navigation menu of my website The link to my website is < and when you load it on your browser, for a few initial loading seconds, you will notice that the menu items are visible at the top left side of the website along with the logo. I don't know what to do about it. The menu items are supposed to be activated if someone clicks on the menu button on the top right corner of the website. I don't have a clue about it. I would really appreciate some help from your side. Here is a screenshot. ![enter image description here](
It looks like your javascript (which is formatting your menu) is only running after page load. You have quite a few includes so I didn't check them all, but make sure your theme is running its setup script on document ready. Like this (for jQuery). $( document ).ready(function() { //run script here }); Also, you could try manipulating the menu CSS. The id for the div around the menu is "sidr". Try adding "display:none" or "height:0" and see if the menu still works properly. You could also speed up page load a little by optimising images - you have about 4.3Mb of images on the index page at the moment - which is a lot.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "menus, javascript, navigation" }
How to seperate static phrases from template files in custom theme? I am looking for best practise patterns how to separate static phrases (e.g. button labels, status messages) from the actual template files when developing a custom theme? It is not necessary to make such phrases dynamically accessible as real WP content. My research lead to the topic of internationalisation (< However, to me I18n appears a bit too much of an overhead for my purposes. I am thinking of a separate phrases file which gets included, say, in header.php (or rather functions.php?). There, phrases would be defined and assigned to variables or constants, which could be used as place-holders in template files. example file phrases.inc.php define('SEARCH_BUTTON_TEXT', 'Search'); ... define('FILTER_SUCCESS_MESSAGE', 'Your filter results'); Any ideas?
Your research lead you to the correct answer. Internationalization (A.K.A i18n) is best practice and is not as complicated as it may seem. You'll be better off in the long run learning it now. @Pieter Goosen is 100% correct with his advise in response to your suggestion using variables and constants. > Keep out of global scope (creating globals and constants), it is a really messy and evil place to be. Wordpress has already made a huge mess of this, don't go and dirty it even further. You should avoid creating globals and constants at all costs. As already stated, l18n is a much much better way and also the correct way of doing localization.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, templates" }
Show only posts which can be commented I have a pre_get_posts filter to show exclude some posts on the homepage. But I can't exclude the posts which are closed for commenting. How do I do this? What I have is: function wp_filter_pre_get_posts( $query ) { // Only modify when on homepage & only the main query if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'comment_status', 'open' ); $query->set( 'tag__not_in', '188' ); $query->set( 'posts_per_page', '3' ); } } add_filter( 'pre_get_posts', 'wp_filter_pre_get_posts' ); Excluding the post from category 188 works fine, but excluding the posts with closed comments does not. Any hints?
Because `comment_status` is not a built-in query argument - but you can easily implement it: function wpse_214323_query_by_comment_status( $where, $wp_query ) { global $wpdb; if ( ! empty( $wp_query->query_vars['comment_status'] ) ) { $status = $wp_query->query_vars['comment_status']; if ( $status !== 'open' ) $status = 'closed'; $where .= " AND $wpdb->posts.comment_status = '$status'"; } return $where; } add_filter( 'posts_where', 'wpse_214323_query_by_comment_status', 10, 2 ); Use this in addition to your existing code, now you can query `'comment_status' => 'open/closed'`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "comments, pre get posts" }
Can you set envelope sender used by wp_mail? Is it possible to change the envelope sender used by `wp_mail`? So far I have tried setting `headers`, and the `wp_mail_from` and `wp_mail_from_name` filters.
Yes. You can. There is several filters what you mentioned in your question. You can do it with WP Mail SMTP plugin. This plugin have multiple settings such as: Sender Name, Sender Email. To get it to set the envelope sender as well, you have to turn on the "Return Path" option. This stuff working with using filters which you've mentioned. You can also setup an external SMTP server which should be using to send all emails in WordPress.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "wp mail" }
Filter page title (displayed in browser tab) of wp-login For wp-login.php, the default page title, **as displayed in the browser tab** , is "Log In". I need to change this value using a filter in functions.php. Every solution I've read addresses the head **er** title but I need to modify the head title.
I don't see a filter in wp-login for the title, but it does use `__()` so you might be able to use the `gettext` filter like: add_filter('gettext', 'wpse_214367_change_login_title', 20, 3); function wpse_214367_change_login_title( $translated_text, $untranslated_text, $domain ) { if( "Log In" == $untranslated_text ) $translated_text = "My New Title"; return $translated_text; } EDIT: Please try this and let me know if it works. May also need to add a check to make sure you are on wp-login.php page add_filter('gettext', 'wpse_214367_change_login_title', 20, 3); function wpse_214367_change_login_title( $translated_text, $untranslated_text, $domain ) { static $count=0; if( "Log In" == $untranslated_text AND $count === 0 ){ $translated_text = "My New Title"; $count++; } return $translated_text; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters, login, title" }
How to get a post's associated taxonomies and terms in wp api v2 I am using angular to get a list of posts back from the post endpoint for the wp api. These posts have different taxonomies and terms associated with them. I want to use angular's search filters to quickly get through the list but I want to do it on each taxonomy's terms associated to the post. The problem is, the post endpoint does not show associated taxonomy or terms for each post. What's the best approach here?
Ok, I just stumbled upon the answer buried deep in the github issues page: < The answer is: > the reason is that the terms / meta etc are different objects, and in typical REST design going a GET on a single resource, will give you that resource, not that resource and a bunch of other ones too. However, you can pass _embed to the request which will include the linked resources in the response, for example see <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "terms, api" }
Do uploaded plugins get updates if they came from the wordpress plugin directory? I'm a plugin developer and want to ensure my users are getting updates when I release an update within the wordpress plugin svn repo. I know if they search for the plugin through the plugin area of their admin and install it that way that they see updates. However I'm not sure if people download the zip file from the public wordpress plugin listing, ie from a page like this, and then upload it manually to their wordpress installation, is it still linked like the previous method where they will see updates if there is a newer version in the wordpress plugin svn repo? I'm ultimately trying to figure out if I should direct future users to the plugin description page on wordpress.org, or if I instead should be telling them how to search for it within their wordpress admin.
Here is how you should be updating your plugin. The WordPress install sends data to the repository and the repository sorts out the versioning and talks back to the install. Here is an article by Mark Jaquith on this subject, and the lengths to go though to turn it off. > There has been a vigorous discussion going on regarding what data WordPress installs send to WordPress.org when doing update checks. Because WordPress (the software) doesn’t know whether a theme or plugin is listed in the WordPress.org repositories, it has to check them all, and let the repository sort it out. Some have expressed concern that private plugins developed for a single client could contain sensitive information in their headers, like contact information for the developer, etc.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, plugin repository" }
Filtered table in wordpress I am Developing a alphabetical filter table in wordpress template. But filter is not working may be because of code below. if($char) { $results = $wpdb->get_results( "SELECT * FROM teacher_directory where Name LIKE '$char%'", ARRAY_A ); $count = $results->num_rows; if($count >= 1) { //Printing the table here } In the above code `$char` is taking the letters but list is empty.
> Ok I got my answer if($char) { $results = $wpdb->get_results( "SELECT * FROM teacher_directory where Name LIKE '$char%'", ARRAY_A ); if(!empty($results)) { //Printing the table here } }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php" }
Why does WordPress have a noop.php file? While configuring Ctags to recognize WordPress functions, I came across the noop.php file. Here is an excerpt: /** * @ignore */ function add_action() {} /** * @ignore */ function did_action() {} /** * @ignore */ function do_action_ref_array() {} **Why does this file exist?** Can I remove it to let VIM better navigate the code?
The description on top of the page you have linked gives an explanation: > Create a new file, `wp-admin/includes/noop.php`, which loads all of the noop functions for `load-script|styles.php` and is only loaded by those files. DRYs in the process. See #33813. Additionally there is the trac ticket #33813 linked, which gives some additional insight. You generally shouldn't delete core files so consider `noop.php` as a necessary file.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 6, "tags": "plugin development" }
How to check which submission button was clicked? So I added a new submission button to the edit page: Using the `post_submitbox_misc_actions` hook with the `submit_button($text, $type, $name);` function. I wanted to modify the data that's saved based on what button the user clicks. So if the user clicks on the regular update/submit button then the post would save normally. However if the user clicks on the new button, then I would modify some information about that post. I was planning to use the `wp_insert_post_data` hook to modify the data, but the problem is that I don't know what button the user clicked (using php). So my question... is it possible to identify which button the user clicked using a hook (or some other method)? Or, is this not the correct approach? And I should use some other method to interfere the save action? Update: I also tried logging $_GET and $_POST to see if there was any relevant information there, but couldn't find anything.
The function `submit_button()` does generate: <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" /> As seen on the codex documentation page. Which gives you the possibility to check for a `$_POST` or, depending on the form, `$_GET` or generic `$_REQUEST` variable - to be exact for `$_POST[ 'submit' ]` or `$_GET[ 'submit' ]` or `$_REQUEST[ 'submit' ]`. The key for the variable is determined by the `input` tags `name` attribute value, which you can change for `submit_button()` by making use of the `$name` parameter.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filters, hooks, customization" }
How to provide value for 'selected' on wp_dropdown_categories() for 'multiple' options I'm using `wp_dropdown_categories()` with `multiple="multiple"` in this way, bypassing WordPress core. Till now (WP 4.4.1) doesn't support `multiple` on that select field. (Core Ticket) I'm struggling with the `selected` parameter. How can I pass multiple values so that the `selected` parameter can understand which multiple options to be selected? I think it's possible only by writing own function supporting array values for selection. Any easy way?
Thanks @markkaplun. I solved it writing my own: <?php /** * Dropdown for 'my_tax' * @since 1.0.0 Using wp_dropdown_categories(). * @since 2.0.3 Custom code, as wp_dropdown_categories() doesn't provide * 'selected' field for multiple="multiple" */ $my_tax_terms = get_terms( 'my_tax', array('hide_empty'=>false) ); echo '<select required multiple="multiple" name="my_tax[]" id="my-tax" class="postform">'; foreach ($my_tax_terms as $tax_term) { $selected = !empty($_POST['my_tax']) && in_array( $tax_term->term_id, $_POST['my_tax'] ) ? ' selected="selected" ' : ''; echo '<option value="'. $tax_term->term_id .'" '. $selected .'>'. $tax_term->name .'</option>'; } echo '</select>';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories, dropdown" }
Difference between WordPress stand alone & through host gator I am new to WordPress development, I noticed a certain thing in the pricing. If I go into www.wordpress.com and try to buy a plan for e-commerce , I am getting a quote of $299 per year but if I buy a domain from host gator and add WordPress through its cPanel, I can add woocommerce for free. What is the difference between the two, I am flabbergasted.
Wordpress.com is just one of the companies that offers you specialized wordpress hosting. all companies that do that come with some restrictions or surprising pricing plans when you compare to "regular" hosting. Since those companies have their own specialized enviroment in which wordpress runs, which they rarely reveal the details of, it is hard to compare between them and self hosted wordpress. The distinction is usually mainly about not having to maintain the server level processes and the specialized wordpress support. So in principal the 299$ you pay to wordpress.com is for some extended tools like caching and CDN and support which specializes in woocommerce. Does it worth the money? maybe for people that lack technical knowledge to handle hosting by themselves or people that don't have it in house and do not want to depend on freelancers.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -3, "tags": "hosting" }
Woocommerce checkout column total too small can not get it wider On my site I have problems to get the total column wider. I work with a child-theme. In the .css of it I declare this: .woocommerce-checkout .checkout .shop_table .product-total { width: 30%; } or .woocommerce-checkout .checkout .shop_table td:last-child { width: 30%; } Both are recognized. But did not help at all. See that there are more users fighting with the small total column. Does someone of you have a suggestion how to solve this via a child-theme? Thanks for reading this thread.
I have got the solution from avada theme makers: .checkout .shop_table tfoot th { width: 85% !important; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": -2, "tags": "woocommerce offtopic" }
load_plugin_textdomain error I receive this error while debug mode is enabled: > Notice: load_plugin_textdomain was called with an argument that is deprecated since version 2.7 with no alternative available. in /home/xyz/public_html/wp-includes/functions.php on line 3739 I found that is related to this plugin: < I really need to have this plugin and would not ignore it; Also plugin author had not responded about this issue. Could you please guide me to modify it?
The plugin calling `load_plugin_textdomain()` the wrong way: load_plugin_textdomain( 'custom_smilies', PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/lang' ); You have to change the code to: load_plugin_textdomain( 'custom_smilies', false, plugin_dir_path(__FILE__) . '/lang' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, functions" }
Security: blocking direct access of php files I found 2 ways to block direct access to php files (although it's not always necessary, see < The first one is: defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); And the other: if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) { die ( 'You do not have sufficient permissions to access this page!' ); } Are they doing the same thing? Shall I prefer one to the other?
In my opinion, the **only** way to do this (within the context of WordPress) is: if ( ! defined( 'ABSPATH' ) ) // Or some other WordPress constant exit; The second technique is vague and does give the same level of checking (it only checks that the filename of the main PHP file matches itself, not whether WordPress is loaded, nor if it's another file of the same name). And this `No script kiddies please!` is pointless, I wish this fad would die - just exit silently.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "php, security" }
Changing next and previous post link text So I've been staring at the CodeX for about 10 minutes and can still not figure how to do this next and previous on a the post page. So I've added `<?php next_post_link(); ?>` and `<?php next_previous_link(); ?>` to my page and works perfectly but I want it to say Next Post and Previous Post instead of the blog title. I've done this `<?php next_post_link('% &raquo; &raquo; ', '', 'yes'); ?>` copied and pasted it straight from the WordPress CodeX and not even that works it gives me the two arrows and a percentage sign. Am I doing something wrong? I'm grateful for any help :) Regards, Stephen
Use the following for with Custom Text with Link. The above given code by @TheDeadMedic works only with text but no link. Code With Link and Custom Text like this: <?php previous_post_link( '%link','Previous Post' ) ?> <?php next_post_link( '%link','Next Post' ) ?> Hope this helps.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "posts, theme development, blog page, codex" }
How do I link to a php file in my plugin directory? Basically in the `wp-admin` section I have a page where I attempt to export some records from a grid. I have an Export link which leads to something like `admin.php?page=download&selected_ids=1,2,4`. But when I click it I get the following error: > You do not have sufficient permissions to access this page. I think I need to first somehow register this page into WordPress before I can reach it through the URL. The page is just a download script called `download.php` so I don't want it to appear anywhere. It's only there to allow me to export some things and it's located in `my-plugin-directory/lib/download.php`.
You can use `admin.php?action=my_action` and WordPress will fire the equivalent action hook: // How to get the URL $url = admin_url( "admin.php?action=wpse_21460_export&any_other_arguments" ); // How to handle the URL function wpse_21460_export() { // Do your export and exit } add_action( 'admin_action_wpse_21460_export', 'wpse_21460_export' ); See how WordPress formats the hook name to `admin_action_{value_of_action_param}`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, wp admin" }
Where can I find the SQL to get the most used information by wordpress database? I tried to google "`wordpress sql to get post url`" and I was pretty astonished I couldn't find any resource sharing the **`SQL code`** to join the `wp_post` table with the table containing the **permalink**. How would you face this 'challenge'? Is there any resource sharing this kind of information?
> I tried to google "wordpress sql to get post url" and I was pretty astonished I couldn't find any resource sharing the SQL code to join the wp_post table with the table containing the permalink. That is because there is no table containing the permalink. Your "challenge" and your "astonishment" are because you've imagined the system to work in a way that it doesn't. The permalink isn't stored anywhere. It is calculated based on the permalink settings in the backend. If you want to see how that happens, take a look at the source code for `get_permalink()`. The only thing saved to the database is the permalink pattern, which is saved to the options table under the `permalink_structure` key and looks something like: /%year%/%monthnum%/%day%/%postname%/ But, of course, that varies for the numerous different structures possible.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "query, sql" }
when use function the_content break i use the function below to show content under the_content. It works on pages which uses template-test.php. But on other pages the_content stops output. function beschreibung_kriterien( $content ) { if ( is_page_template( 'template-test.php' ) ) { $content .= '<h2>Test</h2>'; return $content; } } add_filter( 'the_content', 'beschreibung_kriterien', 5 );
Because you only return `$content` from inside your `if` \- you should _always_ return it: function beschreibung_kriterien( $content ) { if ( is_page_template( 'template-test.php' ) ) { $content .= '<h2>Test</h2>'; } return $content; } add_filter( 'the_content', 'beschreibung_kriterien', 5 ); This just goes to the show the importance of proper indentation!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters" }
WooCommerce - Query for ordered products I'm trying to obtain all orders for particular day/time and then order products using SQL (MySQL) as seen in the query below: select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = '_product_id' and p.ID = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta as im where p.post_type = 'shop_order' and p.ID = pm.post_id and p.ID = i.order_id and p.post_date BETWEEN '2016-01-14 00:00:00' AND '2016-01-14 23:59:59' and p.post_status = 'wc-processing' It looks like when I try to query `wp_woocommerce_order_itemmeta` table for ordered products data I'm loosing connection to a database (connection timed out during a query). Any clue what is going on?
Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta as im where p.post_type = 'shop_order' and p.ID = pm.post_id and p.ID = i.order_id and p.post_date BETWEEN '2016-01-14 00:00:00' AND '2016-01-14 23:59:59' and p.post_status = 'wc-processing' Explanation: Post ID has no direct relation to the order item meta
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "database, query, woocommerce offtopic, mysql" }
Hide sub menus sometimes I have the following css: nav ul ul { display: none; } It hides sub-menus for me. It works too well. I'd like the sub-menu to be visible _iff_ the parent menu item is the parent of the selected item. Is there an easy way to do this?
Try using the following code. .current-menu-ancestor > ul { display:block; } The class current-menu-ancestor appears if the current item is a parent of a current page item.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "menus" }
How to display user's avatar on their profile page? I'm trying to figure out a simple way to display the user's avatar on their profile page. It seems like it would be a very simple thing to do, but I can't figure it out. Is get_avatar(); not the right way to display it?
You didn't add any code _(make sure you add your own code next time because nobody bothers to help you if we have to guess the problem)_ but Im pretty sure I know what's wrong. Straight out of the WordPress codex: echo get_avatar( $user_id_or_email, $avatar_size, $default_avatar, $alt_text, $args ); * * * You **have to** `echo` it because `get_avatar()` doesn't output it by default. Also make sure that _" Show Avatars"_ is checked in _Settings_ because it will not return avatar otherwise.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "user meta, profiles, avatar" }
get_query_var('post_type') not returning in a filter Trying to highlight custom taxonomy pages in the main nav, so I am trying to get the `post_type` of the current rendered page (to compare to the menu item): add_filter('nav_menu_css_class', 'current_tax_nav_class', 10, 2); function current_tax_nav_class($classes, $item) { $post_type = get_query_var('post_type'); echo ">>>"; print_r( $post_type ); echo "<<<"; return $classes; } But cannot get post_type var to return anything. This code is in functions.php Using WP Version 4.4.1
If you are trying to get the post type for the current 'post', I think you could go with `get_post_type()`. Like this: $post_type = get_post_type(); Try it out.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "menus, navigation" }
Code Blocks with WYSIWYG in blog post Is it possible to format code in the wysiwyg editor, up to now I use Blockquotes to represent code, but my problem is that it does automatically line breaks, and I don't want to have random line breaks in my code.
There are several ways to deal with this problem. You could have a look for some syntax highlighter plugin, those will also bring you coloured text with highlighted keywords etc. pp. This is probably nice, if you use code quite often. I use SyntaxHighlighter Evolved. If you want to do this by hand, `<code>` is probably the HTML-element you want to use, just like Stack Overflow does, too. It´s "designed" to be used that way (and understood as code from a semantical view, too). If you want to prevent line breaks, you can add this to your CSS: code { white-space: nowrap; } You have to use this in the text view of the editor though, as the WYSIWYG version would probably strap it out. You can get around that by defining a shortcode for your code-tag. You will find lots of examples for that around the web.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "posts, formatting" }
Custom WordPress Dashboard for Specific user role I want to customize dashboard or 1st page when user login into admin panel. This will be for Author/editor where he/she will only see some tabs/button of the pages and posts, by click them he/she can land on the page/post edit page. ; I am pretty sure that "index.php" file will be edit under "wp-admin" folder but I just need some step by step guideline on this. 2nd thing I want Publish/update button to be shown below the content editor while hiding the right sidebar. I have tried it but couldn't find a clue. So any hep would be much appreciated.
Basic implementation: 1. Create a page for the frontend (and optionally a template). 2. Then add the following code to your `functions.php`: * * * function login_redirect_capability() { if ( current_user_can('author') || current_user_can('editor') ){ return 'url-of your custom page'; } } add_filter('login_redirect', 'login_redirect_capability'); This will redirect them to the page you created. If you want to recode the dashboard as in the Wordpress admin backend, you can look at the code in this plugin to see how it's done. However, if you're new to this, I highly suggest against that. An alternative to a backend dashboard would be something like this. If you have a site that requires members I suggest looking into using a membership plugin which would make that a whole lot easier.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp admin, dashboard" }
Search one custom post type ONLY, disable "all posts" I have the searchform.php set up to search a custom post type and a category. So far so good. However, a savvy user could edit the URL to remove "post_type=film" and search all pages and posts. I don't want it to do this! I'd essentially like the search hardcoded to only search the specific CPT regardless of what is in the URL slug. Is this possible? search.php contains this: <h1><?php echo sprintf( __( '%s Search Results for ', 'site' ), $wp_query->found_posts ); echo get_search_query(); ?></h1> <?php get_template_part('loop'); ?> <?php get_template_part('pagination'); ?>
I guess you mean overriding the post type of the main search query on the front-end. You could try: add_action( 'pre_get_posts', function ( WP_Query $q ) { if ( ! is_admin() && $q->is_main_query() && $q->is_search() ) $q->set( 'post_type', 'film' ); } ); This way you don't need a secondary search query or mess directly with the globals.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, search" }
Adding a body class with ACF I have created a radio button field with ACF so that admin can specify a colour. E.g: * blue : Blue * pink : Pink I'd like this to be output as a class via `<body <?php body_class(); ?>` in header.php. Is this possible? I'm currently outputting the class in header.php like so: <div id="page" class="site <?php the_field('package_colour',$post->ID); ?>">
Hook into the `body_class` filter and add your field there. It might be better to get the ID from `get_queried_object_id()` instead of `get_the_ID()`. add_filter( 'body_class', 'wpse_20160118__body_class' ); function wpse_20160118__body_class( $classes ) { if ( $package_colour = get_field( 'package_colour', get_queried_object_id() ) ) { $package_colour = esc_attr( trim( $package_colour ) ); $classes[] = $package_colour; } return $classes; }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "advanced custom fields, body class" }
Different fields available for different sites when when customising Menu's I have 2x websites, both running identical versions of the same theme, yet when I try to customise the menu's I'm met with different field options. On Site A I am able to add settings to fields such as **CSS Classes** , **Link Relationship** and **Description** , however on Site B those fields are not available. Neither site has custom customisation settings, and a brand new install of the theme on a clean DB results in the same settings availability as Site B. I'm a little stumped by this strange behavior, has anyone experienced this it before? The images below show the fields available when adding a Custom Link (both via the Custom Link option, and the pseudo Home link under Pages). I have however confirmed that this behavior persists when adding things like Categories, Tags and Posts to the menu. !Site A !Site B
This is most likely a result of different Screen Options selected between each site. While on the menu editor, look in the top right corner for the Screen Options pull down. On that panel, you should have the option to hide or show (via checkbox) details such as the title attribute, link target, CSS classes, etc.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "menus, theme customizer" }
WooCommerce: Webhook disabled on its own I'm developing an order management system that hooks into WooCommerce but the Webhook behaves irregularly. The Webhook gets disabled on its own. I've investigated with the users - none of them have privileges. The administrator hasn't touched this section and hasn't updated any of the plugins. Are there any reasons this would happen? Maybe returning http errors from my side? WordPress: 4.4.1 WooCommerce: 2.3.8
Apparently a WooCommerce Webhook will automatically disable due to delivery failure. < > “Disabled” (does not deliver due delivery failures).
stackexchange-wordpress
{ "answer_score": 6, "question_score": 7, "tags": "woocommerce offtopic" }
Resize existing library images How can I resize images that were already in the Media Library when I created new custom image sizes? I just want WP to process them as if they're new images, taking into account my new settings, creating versions for the new custom sizes. I'm sure this must be possible. Thanks!
After some intensive Googling I discovered a couple of plugins for just this purpose. This is the one I used: Regenerate Thumbnails
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "uploads, media library, images" }
Wrong url for the images while using same database for two Wordpress installations I have revamped the site hosted at ` and trying to run the new version of the site at ` **But i want to use the same database with all the links as< Now according to this < i did the hack in wp-includes/options.php as following if ($option == "siteurl" || $option == "home") { // some sample logic to determine if we're on the dev site if (strcasecmp($_SERVER['REQUEST_URI'], '/newsite') == 0 || strcasecmp(substr($_SERVER['REQUEST_URI'], 0, 5), '/newsite/') == 0) { return " } } Everything else is working fine but except for the images. Path for the images is still instead of I am stuck. Plz help!!
That little hack just "fixes" the URL when you call the `home` or `siteurl` options, image paths are not affected by that. Depending on where you want to show images, you could apply a filter to `the_content`, search for your URL and add your subfolder to it. Then you could show images in your post content. I don´t know if there is a better, "wider" filter to capture all output, but this might get you going...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database, options" }
Can anyone tell some online tuts for plugin development for beginner? I am new to WordPress Theme development. I want to learn plugin development.
A good place to start is creating a plugin to replace adding code to your functions.php file and making it "must use". That way your code additions are independent of your theme. It's basic and useful and won't be accidentally removed, or disabled. < < Hope that helps! PS I'm new, so please excuse me if I've done something wrong!
stackexchange-wordpress
{ "answer_score": 0, "question_score": -2, "tags": "plugins, theme development, customization" }
Using esc_url with a hard coded url I've added following URL in my theme, but I have been informed that I must use `esc_url()`. I could not figure out, how can I use that function with following code? <a href=" echo urlencode( get_the_permalink() ); ?>&amp;media=<?php echo urlencode($thumbnail); ?>&amp;description=<?php echo urlencode( get_the_title() ); ?>" target="_blank">Pinterest</a>
I you think you need it. For example, you are using the title in a URL and you are getting the title dinamically; so you never know exactly if the title is valid to be used in URL or not. So, it is better to use it. Just one example: it is very common that titles contain white spaces and white spaces need to be enconded to be used in URLs. I would build the full URL string first and then I would use `esc_url()` at moment it is used for some attribute value. $url_params = array( 'url' => get_the_permalink(), 'media' => $thumbnail, 'description' => get_the_title() ); $url = " . http_build_query( $url_params ); echo '<a href="' . esc_url( $url ) . '">Pinterest</a>';
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, themes, security" }
Does WordPress $wpdb functions wait when table is locked? Does WordPress' `$wpdb` functions wait when the table is locked? For example Function A() uses `$wpdb->getresults`. When `$wpdb->getresults` wants to read a table and its locked, does it wait for unlocking?
By itself `wodb` doesn't do (and probably can't) anything extra to what the DB will do. When the table is locked you will probably wait longer for a response or fail on timeout.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "database, wpdb" }
do_settings_sections() doesn't escape quotes I'm using the Settings API on a custom settings page: <form action='options.php' method='post'> <?php settings_fields('myplugin_settingsPage'); do_settings_sections('myplugin_settingsPage' ); submit_button(); ?> </form> It's a very simple simple settings page, with a few text input fields. The problem is, some of the fields' values contain double quotes (for example, `Jhon "cracy" Garcia`), and it seems Wordpress doesn't escape this character. The value stored in the database seems ok, I've checked it. But, when you visit the settings page a second time, this is the HTML generated by Wordpress: <input name='myplugin_settingsPage[name]' value="Jhon "cracy" Garcia" size=40> As you can see, the quotes aren't being urlencoded so the generated HTML is broken. Am I doing something wrong? Is it a bug in Wordpress?
I found the problem. You need to escape the values in the _render functions, using `esc_attr`, like this: function my_setting_render() { $options = get_option('my_option_name'); ?><input name='my_option_name[my_setting]' value="<?php echo esc_attr($options['my_setting']);?>"> <?php }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "settings api, encoding" }
Post with certain term and without any term I try to create a plugin to manage user groups with permission to view posts within group and I stopped because of query problem. Example: User belong to group called "Group #1" (slug: group-1). I assigned 1 post to "Group #1" and "Group #2" (1 post in 2 terms), 1 post to "Group #2". 1 post is without any group term so it should be visible to all groups because of no assignment. So in the end user should get 2 posts to display. How to build a wp query (if it's possible) or how to create a sql query to get all post without any term and with terms assign to current user. Any ideas?
This should be possible with the `tax_query` parameters for `WP_Query`. The query is either for posts where any term `NOT EXISTS`, `OR`, for any posts where the term IDs are `IN` the provided array. 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'group', 'operator' => 'NOT EXISTS', ), array( 'taxonomy' => 'group', 'field' => 'term_id', 'terms' => array( 23, 42 ), 'operator' => 'IN', ), )
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query, terms" }
COOKIE_DOMAIN setting confusion I'm upgrading my website and it's using WordPress. I'm using sub-domain `cdn` for CDN and it needs to be cookieless. Currently my website is a multi-network of multisites (both are subdirectory installs), with the subdomain `www` hosting my main music project, and subdomain `photo` hosting my photography project. The plugin I'm using for that kind of multi-network is: < I need to use Single Sign-on. And this leads me to a confusion while setting `COOKIE_DOMAIN` in `wp-config.php`. I can set like the plugin's documentation said: define( 'COOKIE_DOMAIN', 'mydomain.com' ); but I know this would make cookies served from `cdn.mydomain.com`. How can I set `COOKIE_DOMAIN` in order to serve cookies from only two subdomains `www` and `photo`? Or do I have to use another domain name just for CDN?
As `cdn.mydomain.com` is not part of your WordPress network, it wont be affected by your settings. The `COOKIE_DOMAIN` constant should only be used if you want to serve cookies from a single domain _for all your sites in the network_. If you omit the constant or set it to an empty value, cookies will belong to the domain their requested from. Thats the configuration you want to use for multisite/network environments especially when it comes to different domains.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "multisite, wp config, cookies, cdn" }
Cannot load admin-ajax.php. No access-control allow origin* I cannot load `admin-ajax.php` and I keep getting this error message: > XMLHttpRequest cannot load ..../wp-admin/admin-ajax.php.,. No 'Access-Control-Allow-Origin' header is present on... On local WAMP it worked just to add this: header("Access-Control-Allow-Origin: *"); (Even if this seems very stupid because next time WordPress updates I guess this would disappear.) When I upload this to my production server it's still the same message: > XMLHttpRequest cannot load ..../wp-admin/admin-ajax.php.,. No 'Access-Control-Allow-Origin' header is present on... I've tried to modify the `.htaccess` file and that seemed to activate CORS, but that won't affect `admin-ajax.php`: <IfModule mod_headers.c> Header add Access-Control-Allow-Origin: * </IfModule> I've also tried to install WP-CORS plugin without success.
There are filters for `allowed_http_origins` and `add_allowed_origins`. You can use them to set the proper Access-Control-Allow-Origin header in the response to your AJAX call. Add this to your theme's `functions.php` file: add_filter('allowed_http_origins', 'add_allowed_origins'); function add_allowed_origins($origins) { $origins[] = ' return $origins; }
stackexchange-wordpress
{ "answer_score": 9, "question_score": 2, "tags": "ajax, headers" }
How to find out when Wordpress version last updated I'm trying to troubleshoot a Wordpress site that has been automatically downloading minor version revisions. I can easily see which version of Wordpress it is using, and I can see on the main Wordpress website when that version was released, but I am not able to see _when_ that version was applied to my site. Is there a way to find this out without logging onto the server to check the timestamp on the files that were updated? Checking this site and Google, I haven't been able to even find someone asking this question. (The bugs we are seeing started around the time WP released the update, so we're trying to figure out if our issues are related or not.) Thank you!
You could check the date stamps of the files on your server, using an FTP client. **Edit:** taking Mark's comment in consideration, it's probably best to check the modification date of the `version.php` file inside the `/wp-includes/` folder of your Wordpress installation. This file should always be modified when Wordpress is updated.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 4, "tags": "wordpress version" }
oEmbded with wp_insert_post() [embedly] I try to add articles via wp_insert_post but as it seems the oEmbed function of Wordpress doesn't work properly. I work with embedly as you can embed any website. I realized that the oEmbed functionallity is triggered after saving the post in the Wordpress-Backend. Can i trigger the Embed somehow programmaticly? Wrap the URL with the Shortcode [embed] is not working.
Read up on Embeds. To trigger an embed use `wp_oembed_get($url)`. In general the url needs to be on it's own line with a space below and above when inside the_content. `wp_insert_post()` has nothing to do with embeds as the embed HTML is usually generated when passed through the_content filter. To add support for non-oEmbed sites use `wp_embed_register_handler()` And for oEmbed-enabled sites use `wp_oembed_add_provider()`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp insert post, embed, oembed" }
Limit filter upgrader_post_install to a single plugin I am using the following filter to run a function that generates a CSS file after a plugin gets updated. Currently the CSS gets generated when any plugin gets updated. Is there a simple way to limit this running to a particular plugin? add_filter('upgrader_post_install', 'generate_my_css', 100, 0); function generate_my_css() { $ss_dir = get_stylesheet_directory(); $pi_dir = plugin_dir_path( __FILE__ ); ob_start(); require($pi_dir . 'includes/css/mycss.php'); $css = ob_get_clean(); file_put_contents($ss_dir . '/css/mycss.css', $css, LOCK_EX); } Ideally the above code would live in the plugin that was being updated but could just as easily live in the functions.php
`upgrader_post_install` has three parameters `$response`, `$hook_extra` and `$result` which give you extra information. At the moment I can't take a look myself, but I'm assuming that especially the `$result` variable should give you additional information to differentiate.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "functions, filters" }
Ordering Taxonomies / Changing term_id I have a site where there are nearly 200 series (custom taxonomy) and roughly 10 items (posts) in each. Each series is called 'Name: _Series Number_ \- One liner bout the series'. When I use get_terms to get all series and order by name I get the order like this. Name: 1 Name: 10 Name: 100 Name: 101 Name: 102 ... Name: 109 Name: 11 Name: 110 Any ideas on how to order this without having to add 001, 002 etc? Alternatively when I order by ID it works perfectly since I added each series one by one after each other. The only issue is during that process I missed a series and only added it after having already added a few more series. For example I was supposed to add series 121 but missed that and went on to add 122, 123,124 and then 121. Now when I order by ID I get 120, 122, 123, 124, 121, 125. Tried manually changing the term_id in phpmyadmin without any luck.
< This plugin does what you want, you can easily manage order.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "taxonomy, order, terms" }
Strange ASCII characters overlapping content I have a Wordpress theme I'm working on. All of a sudden there are random ASCII characters overlapping the nav tabs inside the hamburger menu, font-awesome characters, and social icons. I have tried restoring the mySql database, deactivating all the plugins, and restoring file on the server to reset. Here is the site Thanks in advance.
It seems that error is in your `theme.min.css`. The _Font Awesome Icon_ which should appear in the browser is added via CSS using `content`. But the CSS does not contain the icon information but these weird looking characters. For Example: `.fa-music:before{content:"&iuml;&iuml;&iquest;&frac12;&iuml;&iquest;&frac12;"}` I cannot tell why your minified CSS has these characters. This could be: 1. a bug by Font Awesome 2. or your CSS Minifier is not working correctly. In addition, I see you include Font Awesome Version 4.4.0. You can try and upgrade to the latest Version 4.5.0, which is available at <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugins, text, add theme support" }
Remove lost password form and URL I've shut down password resets for all users. I now need to prevent `/wp-login.php?action=lostpassword` from doing anything should anyone manually input the URL into their browser. i.e. I don't want the password reset form to show. Can I disable the action that's being passed by the URL or can I redirect `/wp-login.php?action=lostpassword` to `/wp-login.php`?
Hi Please try to use this in your functions.php it will redirect user to login form when user try to access lost password page: add_action('init','possibly_redirect'); function possibly_redirect(){ if (isset( $_GET['action'] )){ if ( in_array( $_GET['action'], array('lostpassword', 'retrievepassword') ) ) { wp_redirect( '/wp-login.php' ); exit; } } } Or Please follow below approach used from this answer answered here with some details based on comments of @Clarus Dignus function disable_lost_password() { if (isset( $_GET['action'] )){ if ( in_array( $_GET['action'], array('lostpassword', 'retrievepassword') ) ) { wp_redirect( wp_login_url(), 301 ); exit; } } } add_action( "login_init", "disable_lost_password" );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "redirect, wp login form, password" }
How to disable formatting Everytime I copy something, Wordpress will format the content like it was in that text. For example if I copy a link from Wikipedia, Wordpress will format that word to be bold, blue and with underline. This is tilting me so hard. I have tried the following from Disable TinyMCE autoformatting and I didn't noticed anything remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); I have also tried this plugin, it doesn't work and it generates errors < How to disable formating so that the copied link words will be only regular words? There is a button "remove formatting" but it doesn't do a thing in this case.
Please use this code in your functions.php 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 : This will paste copied text in plain format
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "tinymce, visual editor" }
Child theme functions.php not executing I have the following in a child theme's functions.php file: <?php function theme_child_add_scripts() { wp_register_script( 'script', get_stylesheet_directory_uri() . '/js/script.js', array( 'jquery' ), null, false ); wp_enqueue_script( 'script' ) } add_action('wp_enqueue_scripts', 'theme_child_add_scripts'); script.js isn't included on the page and there's no network request going out to get it. What could be going wrong? It's unclear whether the child theme's functions.php file is even being executed. edit: It seems that the functions.php file is not being executed _at all_ , because I put a die('foo') at the top of the file and the page loaded normally. Why would this be happening? In styles.css: /* Theme Name: Theme-child Template: Theme */
Our problem was that our style.css file was in a css folder inside the child theme directory, not at the root of the child theme. When we placed a style.css file at the root and included the comment block with theme name and template it picked up the functions.php file as expected.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "functions, child theme" }
Retrieving featured image on static blog posts page So I've set up my site to use static pages for the front page and the posts page. Now I'm creating my posts page template. I wanted to grab some content from the actual page I made for the posts page (even though it's no longer really considered a page) and I figured out how to do it...sort of. $posts_page = get_option( 'page_for_posts' ); $title = get_post( $posts_page )->post_title; echo $title; So this will display the title of the "page" in the header area instead of the title of the post. What I need and can't figure out now is how to grab the featured image URL, with a custom thumbnail size with this method. Any ideas?
In your example, `$posts_page` contains the ID of the page for posts, you can use that with any API function that accepts a post ID. For the featured image: $posts_page = get_option( 'page_for_posts' ); $post_thumbnail_id = get_post_thumbnail_id( $posts_page ); $url = wp_get_attachment_image_src( $post_thumbnail_id, 'your-custom-size' ); echo $url; And outputting post title with filters applied: $posts_page = get_option( 'page_for_posts' ); $title = get_post_field( 'post_title', $posts_page ); if ( ! is_wp_error( $title ) ) { echo $title; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, customization" }
Do you need to escape hard coded plain text? I started playing with the Underscores starter theme and noticed it uses `esc_html_e()` even on plain text: <a class="skip-link" href="#content"><?php esc_html_e( 'Skip to content', '_s' ); ?></a> Is it any security risk not to escape it like so: <a class="skip-link" href="#content">Skip to content</a> ... or is it there just for the sake of translation? Thanks.
The security risk here is not about the plain text but about translation. You should note that `esc_html_e` is not only a function for escaping HTML but also for localization (l10n). I.e. other people can translate this String but you don't know what the translation would be. It is possible that somebody translates the String and adds a link or some malicious HTML. Therefore it is better so escape HTML in this case.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "security, html, translation, escaping" }
WP auto redirects after url change? I noticed that WordPress automatically redirects the old to the new page after I made changes to the old url. Are these changes permanent or is it better to add a redirect in the htaccess as well?
Well define "better" ;) If you do the redirect in the htaccess file the advantage is that it will kick in slightly faster as PHP and WordPress is never bothered and the redirect happens right from the server. But practically on an average site this won't really make a noticeable difference. Anyway as long as WordPress isn't changed in future (which is very unlikely to happen in this particular case) this is permanent. So I'd say keep it simple and stick with the default WP behaviour.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "redirect" }
add_page_menu to make shortcut to widgets I want to make a menu button that takes me to wp-admin/widgets.php. The above code seems to work only partially. add_action( 'admin_menu', 'register_widgets_menu_button' ); function register_widgets_menu_button(){ add_menu_page( 'Widgets', 'Widgets', 'manage_options', 'widgets', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 ); } function my_custom_menu_page(){ include ( 'widgets.php' ); I get to the widgets page, but in a peculiar way. Here is the URL that I see in the address bar: wp-admin/admin.php?page=widgets But there is a PHP error breaking the page (I can't see all the widgets). Here is the error: Notice: Undefined variable: wp_registered_sidebars in htdocs/wp-admin/widgets.php on line 403
You can add a link to the `widgets.php` like that: add_action( 'admin_menu', 'f711_add_widgets_shortcut', 999 ); function f711_add_widgets_shortcut() { add_menu_page( 'Widgets', 'Widgets', 'publish_pages', 'widgets.php', '', '', 61 ); } Be sure to check your permission settings, and you may also include another image. You can find the documentation about the function at The Codex.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "widgets, wp admin, add menu page" }
Add a URL prefix to permalinks of one category of posts only I have the permalink structure < which is what I want to keep for most of my posts, however there is one category of posts that I would like to move from < to < Any ideas how I can accomplish this for that one category of posts without changing the URLs of all the other posts?
Suppose `articles` is slug of the category. ### 1\. Add a custom rewrite rule: add_action('init', function() { add_rewrite_rule('^articles/([^/]+)/?$', 'index.php?name=$matches[1]', 'top'); }, 10, 0); ### 2\. Filter the post link: add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false) { if ( has_category('articles', $post) ) { $post_link = str_replace('/' . $post->post_name, '/articles/' . $post->post_name, $post_link); } return $post_link; }, 10, 4); That's all. Try it out in your `functions.php` and remember to flush your permalink structure. **References** : * post_link filter
stackexchange-wordpress
{ "answer_score": 10, "question_score": 8, "tags": "categories, permalinks" }
Querying for specific tags I currently have this code that pulls all of the tags and creates a list with links for them: <?php $tags_array = get_tags(); foreach( $tags_array as $tag) : $tag_link = get_tag_link( $tag->term_id ); ?> <li> <a href="<?php echo $tag_link; ?>"><?php echo $tag->name; ?></a> </li> <?php endforeach; ?> I need to pull only specific tags by ID though. I found the `include` parameter for `get_tags()` on the codex, but I can't find an example that shows correct placement and syntax. I need to query for include="10, 11, 34, 35". How can I do this?
Pass the `array` of arguments with key `include`. $tags = get_tags(array('include' => '10, 11, 34, 35'));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, query, tags" }
Language switcher with flags - Polylang WP plugin I have installed Polylang WP plugin for one site.. and need to add flags but its look like there is no option or any tutorial how to do this.. If anybody have some solution for this will be great..
In meantime, maybe I have on.. I do not want to use some big scripts or something so I did this simple one.. I will write here if somebody else need it.. 1.) I create sidebar in my theme, and add it to header <div class="drop-dl"> <a class="lang-chose" href="#"><img src=""> Chose language</a> <?php get_sidebar(); ?> </div> 2.) Then I go to admin page and on widget section I add Language Switcher to Sidebar to get Unsorted Lists from languages 3.) and I add small script and css code to get this work, here is CodePen demo link Any suggestion is welcome :) Because this solution work with "Polylang widget", the good part is that you have addition options and functionality to chose from widget "Language Switcher" ![enter image description here](
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, plugin polylang" }
Change "You are now logged out" text I want to wrap `<strong></strong>` around the words "logged out": add_filter( 'gettext', 'wpse17709_gettext', 10, 2 ); function wpse17709_gettext( $custom_translation, $login_texts ) { // Messages if ( 'You are now logged out.' == $login_texts ) { return ''; } // Log out message return $translation } ...however adding HTML elements to the text string breaks my page. How can I add `<strong></strong>` to this message text? Is there a means other than `gettext`?
This allows for the message to be overwritten specifically for the `loggedout` message while leaving all other messages alone. Here is more documentation on the filter. add_filter( 'wp_login_errors', 'my_logout_message' ); function my_logout_message( $errors ){ if ( isset( $errors->errors['loggedout'] ) ){ $errors->errors['loggedout'][0] = 'This is the <strong style="color:red;">logged out</strong> message.'; } return $errors; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "filters, login, wp login form, logout" }
Adding Static Image to WooCommerce Content-Single-Product template I am trying to add some static images to the single product template in WooCommerce but they are not displaying properly. I am hooking into the `woocommerce_after_single_product_summary` hook and everything is being included in the file fine. I have added, among other things, the following code: <div class="product-detail-header"> <img src="<?php echo get_stylesheet_directory(); ?>/images/sig-technical.png" /> <h3>Technical</h3> <hr> </div> For some reason the image path is inserting itself after the path of the current page which is obviously not where it should be pointing to. It is translating to ` instead of `C:/wamp/www/wp_project2/wp-content/themes/Divi-child/images/sig-technical.png` I've been racking my brain and can't figure this one out. Any ideas would be greatly appreciated.
Many thanks to Nathan Powell for the fix. Changing `get_stylesheet_directory()` to `get_stylesheet_directory_uri()` will return the correct `URL`. `get_stylesheet_directory()` returns the absolute server path to child or parent theme (hence my previous issue) whereas `get_stylesheet_directory_uri()` returns the properly formed URI of child or parent theme. I suppose the lesson is to pay close attention to exactly what function you're using as WordPress has many similarly named plugins. You can check out the codex docs here: get_stylesheet_directory() & get_stylesheet_directory_uri()
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, images, woocommerce offtopic" }
How do I fix "You are not allowed to edit this item." for Admins on existing posts? I'm doing some work for a new client (non-tech, their former tech person left). Their version of Wordpress is 4.3.2. I have an admin account and I'm unable to edit existing posts. I can create new ones and edit those, but I'm unable to edit existing posts. The edit links don't show and if I put in a url I construct myself like ( _`/wp-admin/post.php?post=1375&action=edit`_) I get this error message: > You are not allowed to edit this item. I have full access to the filesystem, database, etc. how do I fix this issue so I can edit existing posts through the WordPress UX? I see the user Role Editor plugin is installed. I activated it and updated it. It shows that administrators have full permissions. ![administrators have full permissions](
I fixed this by editing /wp-includes/capabilities.php The code was function current_user_can( $capability ) { $current_user = wp_get_current_user(); if ( empty( $current_user ) ) return false; $args = array_slice( func_get_args(), 1 ); $args = array_merge( array( $capability ), $args ); return call_user_func_array( array( $current_user, 'has_cap' ), $args ); } and I changed it to function current_user_can( $capability ) { $current_user = wp_get_current_user(); if ( empty( $current_user ) ) return false; if (is_admin()) return true; $args = array_slice( func_get_args(), 1 ); $args = array_merge( array( $capability ), $args ); return call_user_func_array( array( $current_user, 'has_cap' ), $args ); }
stackexchange-wordpress
{ "answer_score": -1, "question_score": 3, "tags": "admin, permissions" }
How best to display notifications on the front-end using caught exceptions as an example I'm using exceptions in my plugin. function foo() { // Some code. throw new Exception( 'Division by 0' ); // Code continued. } try { echo foo(); } catch ( Exception $e ) { } I'm aware `$e->getMessage()` will give me the caught exception's message, but in the absence of a notifications API, what is the recommended way to display this message to the user on the front-end?
For admin area you can use admin_notices: < For public area (front end) you would probably need to output to some hook and insert the proper CSS. You could use wp_footer() for that, which is present in every theme (or at least should be) and is inside the body tag.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "notifications" }
How to create a WordPress sandbox on a live server for website development? I have a live WordPress site with a coming soon page template currently active. How can I develop the website on a sandbox and then upload all changes to the live site? The sandbox has to be on the same live server, not through local development.
> I have the wp-admin access but I don't have cpanel access. The server is through shared hosting. You can't in any meaningful way put up a "sandbox" given those conditions. You have no way to isolate the code, and you need to isolate the code somehow. As I wrote in a comment, you are putting probably buggy, probably unstable, and potentially insecure code on a production server. You need to isolate-- "sandbox"-- the code where it can't effect anything outside of itself and that means a subdomain, a seperated domain, an independent database, and probably other precautions as well. If you are asking "how" you don't have the knowledge to do this safely. Pay for another hosting package or develop locally.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, sandbox" }
What do with the index.php ... Sorry for my simple question, but I don't know how to explain it right so google won't help me. Therefore I try here to get a answer. So.. i use the front-page.php in my theme as startpage. I know that the index.php is used for all pages which have not set a file.php. My question is: Which code goes in the index.php? The same I used for the front-page.php? Is this useful? My current theme structure: ![enter image description here](
Below is a link to a very good Tutorial made by LearnWebCode on YouTube that teaches you how to make your own WordPress Theme as well as explains what each individual page does and the purpose of the `.php` file . It's what I watched when I first started off making my own WordPress Themes. WordPress Theme Development - Tutorial Regarding your question however - there are many different things you can put in the index.php file it all depends on how many other `.php` files you have. Good luck, Stephen :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development" }
Sort by meta key on archive page I am trying to sort an archive page using a meta key value (which happens to be a Unix timestamp). Currently I have the posts listed on the page by their WordPress creation date. I want to use the meta key - which is a different date than the WP creation date. The code is pretty simple at this point, its just using The Loop to display the posts using a template: <?php while (have_posts()) : the_post(); Template code here endwhile; ?> How do I get the posts to show up by the meta value dates instead of the WP creation date?
Use `pre_get_posts` to alter the main query before it is run. The action runs on every query, use the Conditional Tags to target specific queries. function wpd_sort_by_meta( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'meta_key', 'your_meta_key' ); $query->set( 'orderby', 'meta_value_num' ); } } add_action( 'pre_get_posts', 'wpd_sort_by_meta' );
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "wp query, loop, sort" }
get_post_meta returning broken path in image src I am using a custom field to store the path to an image and then using `get_post_meta()` to insert that path into an `<img>` Here is my code: `<img src"<?php echo get_post_meta( get_the_ID(), 'slide_one_image', true ); ?>" />` For some reason this is outputting `<img src"http: wp_project2 wp-content uploads 2016 01 slider1a.jpg">` which is the correct path but without the `/`'s When I include outside of the image tag it returns the appropriate path, i.e. ` I can't figure out why it is broken when used within the image tag. I have used this exact snippet (grabbing a different custom field value) elsewhere in the site and it has worked perfectly. Any help is appreciated.
I left out the `=` in `<img src="...` So the code should look like `<img src="<?php echo get_post_meta( get_the_ID(), 'slide_one_image', true ); ?>" />` Thanks
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, post meta" }
Get new password without email I had installed a Wordpress theme on my localhost on my ubuntu 14.04. Now, I have forgot my admin password and I am not able to login. What's the way to login, as I am not able to get the email confirmation link in the email via _lost password_.
If you have database access,of course you have because it is localhost. You can update password(MD5) in database. Or if you have not access.You can try code in function.php only one time. <?php $user_id = 1; $password = 'HelloWorld'; wp_set_password( $password, $user_id ); ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "localhost, password" }
'Pages' widget alternative for custom post types? I want to make a menu from a hierarchical custom post type. There is a default WordPress widget called 'Pages' that give you list of all the pages preserving their hierarchy. Is there a way to use this widget for custom post types?
As per first comment, you can use `wp_list_pages` like this: wp_list_pages ( array ( 'post_type' => 'yourcustomposttype' ) );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "custom post types, menus, pages, widgets" }
Does WordPress theme customisation API support section hierarchy? how to create theme customisation section hierarchy illustrated below ? * main section * subsection 1 * subsection 1.1 * subsection 1.2 * subsection 2 * subsection 2.1 * subsection 2.2 * subsection 3 Is this supported out of the box in WordPress theme customisation API ?
Yes, this is supported. They're called panels, sections and controls. Adding a panel uses this code: $wp_customize->add_panel( $panel_name, array( 'title' => 'panel_title', 'description' => 'panel_description', 'priority' => 'priority', 'capability' => 'edit_theme_options', 'theme_supports' => '' )); Adding a section goes like this: $wp_customize->add_section($section_name , array( 'panel' => 'panel_name', 'title' => 'section_title', 'description' => 'section_description', 'priority' => 'priority', 'capability' => 'edit_theme_options', )); Adding the controls is a bit more complicated, but well described in the codex.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development" }
How to run PHP code in Text Widget with no plugin in WP 4.4 Before I had the following code in the function.php add_filter('widget_text','execute_php',100); function execute_php($html){ if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } Then I have updated WP to the version 4.4.1 and now it's not working anymore. Is there any other solution?
Better to write your own widget that does precisely what you need instead of something like this. However, if you really want to execute arbitrary PHP in a widget, use a plugin specifically designed for that task: < I maintain this plugin specifically so that people don't resort to doing things like what you have in your post. The PHP Code Widget is basically a copy of the text widget, but which also runs PHP Code. Nevertheless, PHP Code Widgets are a bad-idea™ and should be avoided. Make a custom widget with your static code instead.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, widgets" }
Standard Loop - wp_query I was readind this article (< and try run the Standard Loop, but I can't receive the any result. My code is this: <?php get_header(); /* Template Name: Page teste */ ?> <?php echo "ola"; // The Query $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata(); get_footer(); ?> This code is on file call "page-test.php". Which is a template for a page on my WordPress.
Yes you need some arguments defined. A good place to easily get your loops defined is: < Here's an example of some arguments used. // WP_Query arguments $args = array ( 'post_type' => array( 'post' ), 'nopaging' => true, 'posts_per_page' => '3', 'ignore_sticky_posts' => true, ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // do something } } else { // no posts found } // Restore original Post Data wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "wp query, loop" }
Disable variations on woo commerce if out of stock I use Woo Commerce on my site with multiple variations on one product. How do I remove or blank out a variation from being selected if I make the product 'Out of Stock'? I've tried using 'Hide Out of Stock' in the Woo Commerce settings though this made no difference.
Managed to solve my own issue. Simply paste the following into functions.php function custom_wc_ajax_variation_threshold( $qty, $product ) { return 10; } add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 ); Then change the 'return 10;' to however many variations you have. **Please note this may slow down page loading time depending on your hosting.**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, plugin development, woocommerce offtopic" }
Why wp_enqueue_style() is adding CSS class? Why my stylesheet links are getting `-css` at the end? How can I remove that ? I have this in my custom function file: function enqueue_styles_scripts() { wp_enqueue_style('bootstrap', get_template_directory_uri() .'/css/vendor/bootstrap.min.css'); } add_action('wp_enqueue_scripts', 'enqueue_styles_scripts'); When I check the source this is the output: <link rel='stylesheet' id='bootstrap-css' href='//localhost:3000/wordpress/wp-content/themes/underscore/css/vendor/bootstrap.min.css?ver=4.4.1' type='text/css' media='all' /> Can you please explain why `-css` is getting added to the given id `bootstrap` ?
The suffix `-css` exists to prevent collisions with other elements on the site. The elements needs _some_ `id` so you can manipulate it later per JavaScript, so there has to be a predictable naming scheme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp enqueue style" }
Query for Custom Post Type UI Does Not Loop All the Post $args = array( 'post_type' => 'lirik_melayu', 'orderby' => array( 'ID' => 'DESC' , ), ); $query = new WP_Query( $args ); $query_contents=Array(); while ( $query->have_posts() ) { $query->the_post(); array_push($query_contents,Array( "id"=>get_the_ID(), "title"=>get_the_title(), "url"=>get_permalink(), )); echo get_the_title()."<br />"; } It will loop until Ten post only.. It should be 14 post! Why it loops until TEN ONLY?
Just found the answer.. Add `posts_per_page` in the arguments as `-1`. It should look like this: $args = array( 'post_type' => 'lirik_melayu', 'posts_per_page'=> -1, // set the limit post to UNLIMITED (-1 is unlimited) 'orderby' => array( 'ID' => 'DESC' , ), ); $query = new WP_Query( $args ); $query_contents=Array(); while ( $query->have_posts() ) { $query->the_post(); array_push($query_contents,Array( "id"=>get_the_ID(), "title"=>get_the_title(), "url"=>get_permalink(), )); echo get_the_title()."<br />"; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query" }