INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
How to remove WPML Generator Meta Tag by theme's functions.php (override plugin function)? I've tried hard to find a way to not let plugin WPML output the following `<meta name="generator" content="WPML ver:2.8.1 stt:3,1;0" />` tag in `<head>` via help of theme's `function.php`: It's called in `sitepress.class.php` beginning with line 255 if ( !is_admin() ) { add_action( 'wp_head', array( $this, 'meta_generator_tag' ) ); } This specific question has already been asked once in WPML forum. I've tried: /* ::: Disable WPML Meta Generator Tag ::: */ if ( ! is_admin() ) { remove_action( 'wp_head', 'meta_generator_tag', 20 ); } add_filter( 'meta_generator_tag', 'theme_generator_tag' ); function theme_generator_tag() { return false; } \-- without success
The instance of this class is made global by WPML, so this should work: if ( ! empty ( $GLOBALS['sitepress'] ) ) { add_action( 'wp_head', function() { remove_action( current_filter(), array ( $GLOBALS['sitepress'], 'meta_generator_tag' ) ); }, 0 ); }
stackexchange-wordpress
{ "answer_score": 10, "question_score": 5, "tags": "plugins, functions, plugin wpml" }
Toolbar/topbar missing on homepage only? My theme seems to have the `<?php wp_footer() ?>` and `<?php wp_head() ?>`, yet it's still not showing on the homepage of my site. However, it is visible on all other pages and posts.
As Mayeenul wrote: Use Firebug/Chrome Inspector to see what's wrong. Look for Javascript Errors in the console see if the Adminbar is inside the DOM but hidden via CSS. It could also be disabled via a filter in PHP with something like this: if( is_front_page() ) { add_filter('show_admin_bar', '__return_false'); } ... but I would say it's more likely that you have an error somewhere in the DOM or in your CSS/JS for the frontpage that is hiding the adminbar.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "themes, homepage, admin bar" }
/wp-admin/post.php shows 404 template on submit When I publish or save a post, I see the 404 error page from my template. This happens with posts and WooCommerce products. I'm using the Twenty Twelve theme, and I have the following plugins activated: WooCommerce, Limit Login Attempts, Google Analyticator. I just installed Wordpress yesterday.
The domain didn't have www. in the wordpress settings. Adding this worked. No idea what the problem was exactly, but this solved it. Edit: Not yet fixed. It was mod_security which blocked 'Wordpress.com.' (I'm at Namecheap which uses mod_security)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "templates, plugins, 404 error" }
How to get particular data from wp_list_comments outside the loop? I need some help,very much new to wordpress. I need only comment title and comment date from `wp_list_comments` function in my post, calling from outside loop, after declared $postid as global variable. Now I am getting all the information about the comment such as author, date,title,comment etc. So how can I get a particular detail as above?
Use `get_comments` function.Pass `Post_id` as parameter.See below example <?php $comments = get_comments('post_id=15'); foreach($comments as $comment) : echo($comment->comment_author); endforeach; ?> for more detail please check below link <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "globals, comments" }
Can wp_list_comments output into variable? Is there any way how to output `wp_list_comments()` into a variable? Something like `$output = wp_list_comments(array('reverse_top_level' => false ), $comments);` I am writing a plugin and it would be handy to use standard WordPress function instead of writing my own.
In the default usage this is impossible due to the nature of the default comment walker which always directly outputs. But the function allows to provide a custom walker. Further reading about custom walkers: Codex Class reference example custom walker class You could also use output buffering to save it into a variable (this is considered to be dirty): ob_start(); wp_list_comments(array('reverse_top_level' => false ), $comments); $variable = ob_get_clean();
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, functions, variables, comments" }
wp_hash_password unexpected behaviour When I run `wp_hash_password("password")` twice the outputs are different. I was under the impression that this is not how hashes are supposed to work. So how should I use `wp_hash_password` to compare two hashes?
That's just not the way it works. `wp_hash_password()` will always return a different value for the same password due to SALTing. You are searching for the wp_check_password() function.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "password" }
Connect to remote database using Localhost install I will be designing and developing a website for a client but want to allow the client to add content while I am working on the design and development of the site so that it is pretty mich done by the time I am finished. Currently, I use XAMPP on port 81 so my project URL looks something like My wp-config file has all the settings I need to the remote DB and yet, when I run the URL it constantly redirects me to I've removed all htaccess files thinking the problem was there but that didn't work. My ISP suggested opening port 3306 which I have done but that's not done the trick either. I don't know if it has to do with port 81 on Xampp perhaps? **EDIT:** General settings link through to the online version of the site so Site Address = < WP Address = < Many thanks
I think s_ha_dum is in the right track, but I think he got it backwards. You want to: 1. develop/design locally 2. connect to the REMOTE database and work with his content? You need a remote (staging) installation of WordPress, where the client can create/enter his content. You need your local WordPress site (localhost) to point to the remote database, to grab the content he is using. So, you would have your < set up for the client to edit - just even with a vanilla WP install. This site would be connected to it's own database. Your localhost site would have the REMOTE site's database credentials, with the `DB_HOST` set to < or whatever the mySQL path is if it's accessed another way through your hosting provider. On your local site, keep the `WP_SITEURL` and `WP_HOME` set to localhost. Otherwise, you'll get redirection loops.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "database, localhost, xampp" }
Create "new pages" within the admin section of plugin Here is my situation, I'm trying to create my first plugin for Wordpress, but I'm having an issue of trying to change the display within the plugin admin page. Here is what I currently have: !enter image description here As you can see I have a couple links on the new page. What I want to do is to change what is being displayed in the window when I click on a link. If this has been asked, I'm sorry, please point me to the post, but I'm not sure how to word what I'm trying to do. I want to be able to change the view based on links that are clicked. So if I wanted to add a customer, I could click on the 'Add Customer' link, and the display a form to add the user, all the while maintaining the admin portion (the links of the left). I hope this makes sense.
The easiest way is to add another $_GET parameter to the URL. In the moment you are viewing `admin.php?page=Customer_Search`. You could make your links go like `admin.php?page=Customer_Search&type=your-page`. In your plugins files you can then output the desired content based on that parameter. if($_GET['type'] == 'your-page') { //output your page ... }elseif( ....other pages ...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, php, plugin development" }
Put password on a wordpress link in a article I've trying to find out how to do this in wordpress and I've searched the web, but I can't find any easy way to make my visitor only see one link if they enter a password to be able to see it. Is there any plugin or solution that could do that ?
I think this is almost what the article Add Private Content to Posts via Shortcode talks about. But it's only for registered users: add_shortcode('private', 'private_content'); function private_content($atts, $content = null) { if ( is_user_logged_in() ) return '<div class="private-content">' . $content . '</div>'; return ''; } And used inside the post/page like: > [private] > This post contains registered-only content! > [/private] To add a password functionality, you'd have to add a `<form>` inside the shortcode function and show the content after the password is successfully `$_POST`ed. Maybe it's more straight forward using Ajax.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "links, password" }
Displaying posts sorting by a custom criterion I wish to display my posts, not according to the date, but to a completely custom criterion. Ideally, I would manually set a numerical value to each post and the WP loop would display posts according to this value. So if post X has value 1, post Y has value 2 and Z value 3, it would display first X, then Y, than Z, even though the date criterion would entail a different order. Hope it makes sense. How to achieve this?
Save the order in a Custom Field, then modify the main query to order on that custom field via `pre_get_posts`. Example for posts page: function wpa_custom_order( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'meta_key', 'your_order_key' ); $query->set( 'orderby', 'meta_value' ); } } add_action( 'pre_get_posts', 'wpa_custom_order' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "sort, order" }
How to install plugin only from PHP file? I have a plugin for Thesis that fixes issues with Wish List Member. The plug is called thesis-wlm. It only has a box.php file. I uploaded thesis-wlm.zip as a plugin and Wordpress attempted to install it but failed. I then added the thesis-wlm folder, which contains the box.php file, to the plugins folder but nothing shows up in the plugins section. There is a plugin header that follows this format: Name: Author: Description: Version: Class: License: Is there some other way to activate this plugin?
Your plugin isn't visible because you haven't provided a `Plugin Name` in your header. Change `Name` to `Plugin Name` and it'll show up. You're also missing a few lines in your header, if that's a concern to you. It's best to just follow the example provided in the codex: <?php /** * Plugin Name: Name Of The Plugin * Plugin URI: * Description: A brief description of the Plugin. * Version: The Plugin's Version Number, e.g.: 1.0 * Author: Name Of The Plugin Author * Author URI: * License: A "Slug" license name e.g. GPL2 */
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "plugins" }
Why I am not able to direct user to my blog section without login? function wpse_41699_wp(){ if( is_page('Login')||is_page('register')||is_page('Blog')||is_page('blog') ){ return; }else{ if(!is_user_logged_in()){ $url = get_bloginfo('home').'/login';//ACW-login location need to be specified header('HTTP/1.1 403 Forbidden'); header("Location: $url"); exit; } } } In the function.php, I added above code, I used above code to disable user access to my site without login, but I want to make regular use able to access blog section which is a page named Blog. but I do not konw why still, I will be direct to login page, while register page is been successufully unblocked from been request to login. Can anyone help me on this one? Thanks!
When you designate a page as the posts page, `is_page()` will no longer be true for that page, as it is now the "Home Page". Use `is_home()` instead to test if the posts page is the current page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "redirect, login, user registration" }
Can I safely remove banned names from WordPress? The banned names list for permalinks appears to be an editable list. Can I remove any of these names? ! My particular question pertains to "blog." I would like to use is as a name for a network / multisite that I am installing.
The slug blog is reserved for the main/root site of a wp multisite setup. In short, _I do **not** recommend trying to use it for something else_ \- it only produces trouble. The slug is hardcoded in some places, so you would have to do some hacky fixes to get around that. Which isn't a guarantee you won't have problems after all. Besides that it's almost certain that those adjustments won't survive the next update, so you have to do it all over again. I could describe how to do it or link you to some how-to's, tutorials out there, but I decided against it, because it's just **not advisable** to do that. So if you really want to try it, you have to find the information yourself - here or on the net. **Note:** Above explanation refers to a _sub-folder_ installation of wordpress multisite, if you are using a _subdomain_ installation you should be able to use < without any problems. In the latter case you can safely remove blog from the banned names.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, permalinks, blog" }
How to edit link for comment count I have recently installed Disqus on my blog and have a problem with the link in the comment count. On the main page here all the comments counts for each post link to the appropriate URL for the post with `#disqus_thread` appended to take the user to the comment section at the bottom. If you navigate to the post by clicking the title like here the link on the comment count changes to `#respond` which doesn't work. How/where do I edit this value to be `#disqus_thread` so it takes the user to the comments below as it should?
I found the section of code I needed to modify in `wp-includes\comment-template.php`: I changed this: return apply_filters( 'get_comments_link', get_permalink( $post_id ) . '#comments', $post_id ); To this: return apply_filters( 'get_comments_link', get_permalink( $post_id ) . '#disqus_thread', $post_id );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, disqus" }
How accomplish modification the_content if home/start page? How can I modify the_content **if** the page is the home/start page? I thought this could be done through a function in functions.php, but soon realized after some googling that the functions.php -file runs before parse query, so WP doesn't now if it is the home/start page or not. What I want to do: If the post have one or multiple images in it, grab the first image and display it in the loop before the content of the post on the home/start page. I don't want to go with "Featured image". How do I accomplish this?
You can check for `is_home()` and `is_front_page()` inside of your filter: add_filter( 'the_content', function( $content ) { if ( ! is_home() and ! is_front_page() ) return $content; return 'Home, sweet home!<br>' . $content; });
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, homepage, the content" }
Extend Custom Post Type A theme I use registers a custom post-type. Unfortunately its supports array misses an item, I would like to add ('thumbnail'). Now, I don't like to overwrite the post-types registration in the theme and instead would like to "extend" it (via my child-theme). Is this possible?
You want `add_post_type_support`. A usage example from the Codex: add_action('init', 'my_custom_init'); function my_custom_init() { add_post_type_support( 'page', 'excerpt' ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, child theme" }
wpdb Cannot Access Associative Array Data in a Count Query I have two records in my custom table. I am trying to use `SELECT COUNT(*) AS total FROM tableA` but I am not getting the results I am expecting. The code below will echo `Array ( [0] => Array ( [total] => 2 ) )`: // Count the amount of records in the table $total = $wpdb->get_results( "SELECT COUNT( * ) AS total FROM tableA", 'ARRAY_A' ); echo "Total Records:" . print_r( $total ); The code below echos nothing: // Count the amount of records in the table $total = $wpdb->get_results( "SELECT COUNT( * ) AS total FROM tableA", 'ARRAY_A' ); echo "Total Records:" . $total[0]['total']; How can I simplify this? What am I doing wrong? I'm racking my brain over this and I just can't get it to work.
You can simplify that by using `$wpdb->get_var`. $total = $wpdb->get_var( "SELECT COUNT( * ) AS total FROM tableA" ); echo "Total Records:" . $total; However, the code you've got should work-- either version of it. I tested both. The only thing I notice is that the first version of the code _should_ give you `Array ( [0] => Array ( [total] => 2 ) )`. Where is `cnt` coming from?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wpdb, array" }
URL of a custom post type's post format archive? With pretty permalinks enabled, the URL of a Custom Post Format archive would look like this: And it works for me. Now, considering that my custom post type archive is located at (where 'bookmarks' is the custom post type's name, registered with `'has_archive' => true`): Isn't the custom post type's post format archive supposed to be located at: But I get an HTTP 404 Not Found Error. Isn't it how it works? If not, how do I access the custom post type's post format archive?
Here's what I finally came to know: _By default, WordPress doesn't have (separate) post format archives for custom post types._
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, archives, custom post type archives, post formats" }
Injecting HTML on (arbitrary) admin pages I would like to create a plugin that is able to inject some html on admin-pages, no matter if these are post, pages, settings or any option page for a plugin. So I am searching for a suitable hook, so that I could run code like this (pseudo-code): function plugin_inject_html() { if( preg_match( '<regexp to parse the url>', $_SERVER['REQUEST_URI'] ) > 0 ) { echo 'my html here'; } } add_action( '<the hook I am searching for', 'plugin_inject_html' ); So my question is: Which action or filter would be suitable to hook in, so that the result of the echo would arrive in the right location of the overall admin-page (inside the `div.wpbody-content`)?
If you check out the source of the `/wp-admin/admin-header.php` page you find the following actions: Inside `div#wpbody`: * `in_admin_header`, Inside `div.wpbody-content`: * `network_admin_notices` * `user_admin_notices` * `admin_notices` * `all_admin_notices` I'm not sure what you mean by the _right_ location, but I guess the `all_admin_notices` action would be the most suitable one for you?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development" }
Meta Query for specific months I have a custom field which stores a date in a timestamp. I want to run a query that display posts based on the month, for example all entries from March, the specific day or year doesn't matter. I'm guessing i need to use the DATE or the DATETIME type for the meta query, but i don't know how to proceed: if ($_GET['month']) { $meta_query[] = array( 'key' => 'event_start_date', 'value' => $_GET['month'] ); } $args = array( 'post_type' => 'event', 'paged' => $paged, 'posts_per_page' => -1, 'tax_query' => $cleanArray, 'meta_key' => 'event_start_date', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query'=> $meta_query ); $events = new WP_Query($args);
You need the 2 digit month number that you want to query on and then use the code below. This should be easy with php (for example, see this post). In the code below `$month` is the number of the month in a 2 digit format, eg March would be 03. $start_date = date('Y'.$month.'01'); // First day of the month $end_date = date('Y'.$month.'t'); // 't' gets the last day of the month $meta_query = array( 'key' => 'event_start_date', 'value' => array($start_date, $end_date), 'compare' => 'BETWEEN', 'type' => 'DATE' );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "wp query, query, meta query, date" }
How to display a widget available for all themes I have just created my first WordPress widget ("hello world" style) and was able to display it correctly. But what I notice that if I change my theme then my created widget disappears from available widget area in admin panel; though there are many widgets which are always showed regardless of chosen theme (Like Text widget). I want to know how can I make my widget available across all the themes?
Put all your custom widget code into a separate php file, add a plugin header: <?php /** * Plugin Name: Name Of The Plugin * Plugin URI: * Description: A brief description of the Plugin. * Version: The Plugin's Version Number, e.g.: 1.0 * Author: Name Of The Plugin Author * Author URI: * License: A "Slug" license name e.g. GPL2 */ then upload it to your plugins directory and activate it. That's it!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets" }
Redirect to custom login page I have created a custom page for login/registration. Is there any automated way to redirect all wp-login.php calls to that page, or will I need to replace all links manually. For example, on the comments form, I have this default message: > You must be **logged in** to post a comment. The _logged in_ links to the How can I change this to:
You can redirect requests to `wp-login.php` to your page: add_action( 'login_head', function() { $parsed = parse_url($_SERVER['REQUEST_URI']); $redirect = site_url('mypage'); if (!empty($parsed['query'])) { $redirect .= '?'.$parsed['query']; } wp_safe_redirect($redirect,301); exit; } ); However, `wp-login.php` appears ~34 times in Core on my 3.6.1 install ( `grep -Rn "wp-login.php" * | wc -l ` ), and many of those do not appear to be filterable. Actually altering all of those links would take some work and may well involve core hacks. The `login_url` filter, and the `logout_url` one, will get you part way, but it do not cover all cases. add_action( 'login_url', function($url) { return str_replace('wp-login.php','mypage',$url); } ); Very rough code. Barely tested. Possibly buggy. Caveat emptor. No refunds.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, themes" }
Where to put code to get custom taxonomy term id? Let me preface this by saying that I am new to Wordpress customization and don't know how to write code, but I can stumble through customizations involving simple copy/paste instructions. So, this question is _very_ basic. Sorry. I'm using a plugin that asks for the term id for the custom taxonomy that I've created. I have found some posts that explain how to do this and give little php snippets (e.g. < But I really have no idea where to put this code. Could you please help? UPDATE: I do know how to create php files via copy/paste and upload to my server, basic stuff like that...
In your WP database there a table named wp_terms. There you can see all terms ids (term_id) and all terms names (term_name). That should give you what you need. If you don't have access to your WP database you can you a plugin to do that. I use one called Adminer, but there are others that do that. Once you install Adminer you can acccess your database from Tools->Adminer - Start Adminer. Another way to do that is to use the function "get_terms". But that involves editing one of your wordpress templates (php files). <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, functions" }
How do you create a development site into a subdirectory of the live site? I have a WordPress site at ` and I want to create a clone development site at ` I want ` to be its own root URL as well as the live one using the same database for both. How would I go about doing this? Daniel
if your using the same database you just copy the entire site over .. if you want to use the same database with its own tables for storage, delete the wp-config file and as your setting up the 2nd Wordpress site just select a different table pre-curser .. the first would be wp_ .. the second may be wp2_ and so on .. with the same database details (name user pass) once you have the site installed you can export the data from one and import it into the other using the Wordpress tools export and import. it sounds harder than it is
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "directory, customization, testing" }
Why is WP creating both "/?tag=" and "/tag/" URLS for same content? I've noticed that WordPress is generating duplicate content with slightly different URLs. For example: Notice that, one is `/?tag=` (i.e. a query) and the other `/tag/` (i.e. a subdirectory). I deactivated all plugins but both URLs were still "200". Can't find any settings to change. Any suggestions for fixing this?
I would like to suggest you to learn how WordPress Rewrite API works. When you learn it, you won't have such kind of questions. Take a look at The Rewrite API: The Basics and The Rewrite API: Post Types & Taxonomies. **TLDR:** The permalink structure like ` is the default approach to determine what should be displayed on a page. In the same time this ` is advanced version of default permalink structure. Internally WordPress will reformat advanced version to `index.php?tag=santas-workshop` and will use it as current request URL. So you don't have to worry about existence of `...?tag=...` URL, it is standard and expected permalink structure for WordPress. Just use your advanced version of URLs. Even more, your theme could support canonical URLs and will add canonical URL meta to each page. In this case Google Bot won't care which URL he will use to grab your page, it will always refer to canonical one found in meta.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "url rewriting, tags" }
How to install wpengine hosted multisite locally Does anyone have any insight into how to install a copy of a wpengine hosted site locally? You can assume Wordpress migration knowledge i.e. I have a copy of the files and have imported the DB locally. I am getting 'Error establishing a database connection' even though I am 100% sure that I have edited the wp-config DB connection details correctly. This is a **multisite** install. **UPDATE** From wpengine : "You will need to remove our platform specific files found in the mu-plugins folder and the object-cache.php found in the wp-content folder...Outside of changing all of the subsite urls and the primary domain, there shouldn't be anything specific to our platform."
I used Search-Replace-DB from < to replace domain urls for the site I needed to develop. I also had trouble with the WP Sharely plugin which was enabled sitewide - it was looking for an activation file on a NAS box in the cloud somewhere. Once I disabled sitewide plugins manually in the DB, I was able to log in and view the site. As advised by wpengine, I removed their platform specific code from the mu-plugins folder and also the object-cache.php from /wp-content I have deleted my wp-config from above for security.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, migration, local installation" }
Clear custom field when new tag is added When adding a new tag in the admin interface, WordPress doesn't reload the page. It appears to send the data with an ajax call, clear the fields and add the tag to the list on the right. I am working with a custom taxonomy that operates like tags. I have added a custom field to that taxonomy. When the user adds a new term, the data in my custom field is not cleared. I have tried using jQuery to clear the fields when the submit button is clicked, but of course this clears the fields even if the tag is not added (if, for instance, the name field hasn't been filled out). Does WordPress offer any callback or hook-like system on the Javascript/jQuery side of things which I could use to execute a function when a new tag is added? I believe I can hack a solution by searching for any fields with the class 'form-invalid' and not clearing my data. But I thought I would check first to see if there is a more stable and future-proof solution. Thanks.
After some experimentation, I found the best hack to be: $('#addtag #submit').click(function () { // Look for a div WordPress produces for an invalid form element if (!$('#addtag .form-invalid').length) { // hide elements and reset hidden field } }); Binding to the click event on the submit button captures both click submissions and submissions where the user hits enter in a text field. The latter were not captured when bound to a submit event on the form element. Checking for the .form-invalid element is not a perfect solution, as WordPress could easily change the class name in the future. But I found it the most comprehensive at catching an empty name field or a duplicate name -- neither of which WordPress will allow to go forward.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, admin, javascript, tags" }
Adding Woocommerce to my own theme, how do I do it? After searching and trying for days, I'm starting to get agitated.. I have a custom theme for Wordpress, wich seems to function OK. But after installing Woocommerce several widget don't work, such as the shopping cart and lightbox. I found out that it has something to do with my theme not being compatible with Woocommerce because when I change to a standard theme everything works as expected. On Woocommerce docs I saw I might have to add some hooks to my functions.php but I can't figure out where to add these hooks... Can anyone point me in the right direction?
Open your FTP browser and go to your WordPress root folder. Find `wp-content/themes/` folder, there should be your theme folder and `functions.php` file inside of it. Open `functions.php` file in a text editor application. Add suggested hooks at the bottom of your `functions.php` file and save it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, plugins" }
I have a question in Basic HTML What does it mean to edit a website directly? My professor tells us not to use an editor. I'm not sure how to do so either.
This basically means you do not want to use, say "Microsoft Word" to edit your code. Doing so may (and often will) add unnecessary bits of information to the code... causing it to parse unexpectedly when viewed in a browser. Instead, you a code editor (like Adobe Dreamweaver, or a free alternative like Notepad++) to edit any code. These types of programs are designed specifically for code editing.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "html editor" }
Is it possible to personalize the Media Library? When we create a new post and click on Featured Image, I realize that WP creates a folder structure "year/month/image.jpg". I'd like to change that behavior to "category_of_the_post/image.jpg" (or maybe "category_of_the_post/year/month/image.jpg"). The reason is that **I want to create a different album of each "category_of_the_post" folder**. I tried different plugins, but **I didn't find any plugin which allow to upload the images at the same time we create the new post** (like when we upload the feature image). Maybe there is some other way to do the same stuff, but I'm beginning with this beautiful CMS so I cannot see the different possibilities from the top.
This plugin might be a solution. WordPress allow you to put uploads in year- and month-based folders. This plugin is somewhat smarter. You can construct paths from variables like post title, category, post author, post date and many more But maybe you've already tried it
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "plugins, uploads, media library" }
How to get the post_name when in preview? I'm using the below code in my `functions.php` file to include some JS only in posts I want. The code works fine for published posts and I can target a specific post, but how do I do it for posts that are not yet published, like viewing a draft post? global $post; if( is_page() || is_single() ) { switch($post->post_name) { case 'post-name-here': wp_register_script( 'charts', " array('jquery')); wp_enqueue_script('charts');
`is_preview()` is supported. You may also want to look into `is_singular()` which covers posts, pages, and attachments.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions, javascript" }
Working with l10n contexts (_x etc) Basic l10n from a .mo file generated out of PoEdit works fine. But as soon as I introduce `_x`, or variants, the link breaks, because as best as I can tell, PoEdit, completely ignores the context, and does not generate the corresponding `msgctxt` line in the .po/.mo files. `_x`, `_ex` and other variants are all added to the keywords, and PoEdit **is** finding and parsing `_x()` occurrences within my source code. It's just not capturing the context and it is not generating the `msgctxt` line in the resulting .po file. What's the workaround ( _other_ than manually editing the .po or .pot file?)
When adding _x to the keywords, try it this way: _x:1,2c This tells the parser to watch out for _x and to take the first argument as msgid and the second argument as a comment, which will then be recognized as context by poEdit and inserted as msgctxt. Oddly enough, my poEdit then shows me the msgid twice in the "new/old" messages window. However, in the messagelist everysthing is correct then.
stackexchange-wordpress
{ "answer_score": 23, "question_score": 8, "tags": "translation, localization, l10n" }
How to check whether a post exceeds 300 words I need to check whether a post exceeds 300 words or not. If it exceeds 300 words, then I have to provide a link to read more about the post.How can I do it? Please help me.I am new to word press.
basically you need to change the default EXCERPT length of your posts. there are a couple of ways to solve this issue: 1. if you aren't familiar with PHP Install this plugin at : < This will allow you to change the the excerpt length from the admin panel. 1. if you are familiar with basic PHP Go to your functions.php in your theme at /wp-content/themes/YOUR_THEME_NAME/functions.php Add the following code: function different_excerpt_length($length) { return 200; } add_filter('excerpt_length', 'different_excerpt_length'); You can change 200 to any number you want like 300. As for showing your summary instead of the full post, you can follow the instructions from wordpress.com like so : < Hope it helps!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts" }
Get themes's images path in WordPress Multisite I have installed a WordPress multisite subdomain network site, so for some blog, it can be accessed with this address I tried to install theme, but it can't access all image used in the theme folder. Is there anythings i need to set up first? such as multisite settings or maybe using .htaccess?
Accessing a Theme's directory in a multisite environment is no different from a single-site environment: * `get_template_directory_uri()` for stand-alone or parent Themes * `get_stylesheet_directory_uri()` for child Themes Please ensure that the Theme has been _enabled_, either globally, or for the specific multisite network site.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, multisite" }
How to get the number of pages when paginating comments? I want to display threaded comments via ajax using pagination. If I use this code to display comments for page 1 how can I know if there is something more to be displayed on page 2? If there is something I would display a link "get more comments" if not there will be no link. $comments = get_comments(array( 'post_id' => $post_id, 'status' => 'approve' )); wp_list_comments(array( 'page' => 1, 'per_page' => 10, 'avatar_size' => 16, ), $comments);
Try `get_comment_pages_count()`? <?php get_comment_pages_count( $comments, $per_page, $threaded); ?> I'm guessing you're outside the loop, since you're calling `get_comments()`; in that case, you'll need to pass your `$comments` object: $comments = get_comments(array( 'post_id' => $post_id, 'status' => 'approve' )); wp_list_comments(array( 'page' => 1, 'per_page' => 10, 'avatar_size' => 16, ), $comments); $comment_page_count = get_comment_pages_count( $comments );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, pagination, comments" }
get_category_parents displays an empty category When I execute '<?php echo get_category_parents(get_query_var('cat'), false, '\' - \''); ?>' on the category page `bar`, which is a sub category of `foo`, this is the output: `'foo' - 'bar' - ''`. How do I remove the last, empty category without PHP functions like `explode` or `substr`?
> How do I remove the last, empty category without PHP functions like `explode` or `substr`? You don't. Look at the source: < The output you see is intended behavior and there is no filter. My guess is that you are trying to use the function for something it is not meant for. You could take another approach and use `get_ancestors` or `wp_list_categories` but `substr` or `str_replace` would be the easiest.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories" }
woocommerce: change default setting > is_sold_individualy function In woocommerce/classes/abstracts/abstract-wc-product.php on line 338. The is_sold_individualy function is default "false". Is there a way to set this default option to "true"? So in de Wordpress back-end the checkbox is checked by default? function is_sold_individually() { $return = false; if ( 'yes' == $this->sold_individually || ( ! $this->backorders_allowed() && $this->get_stock_quantity() == 1 ) ) { $return = true; } return apply_filters( 'woocommerce_is_sold_individually', $return, $this ); } Thanks in advance, Mirjam
You can use a built-in function from WordPress: add_filter( 'woocommerce_is_sold_individually', '__return_true' ); This line in a separate plugin will set the value always to `true`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, plugins" }
Populate a ACF Select Dropdown from Custom Post Type Is it possible to populate an Advanced Custom Fields (ACF) Select Dropdown - options - with all the posts within a specific Custom Post Type (PCT)? Thanks in advance, Ian.
I think you’re looking for this field: < It should allow you to choose any registered custom post type.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "custom post types, advanced custom fields" }
Hook into create_category I'm trying to in some way hook into when a new category is created. What I would like to do is to see the term and slug that was created and log them/email them. I have tried to hook in to create_category(). That only gives me an ID, not the term and slug. Would be great if someone could lead me on the right track.
You could use the get_term_by() function: < // get the category object $category = get_term_by( 'id', $category_id, 'category'); // use the object to get your values $name = $category->name; $slug = $category->slug; Does this help?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "hooks, categories" }
Adding tags and inputs to a user's profile I'm adding a number of items to the user profiles using this method in my `functions.php` function modify_contact_methods($profile_fields) { // Add new fields $profile_fields['twitter'] = 'Twitter Username'; $profile_fields['facebook'] = 'Facebook URL'; $profile_fields['gplus'] = 'Google+ URL'; return $profile_fields; } add_filter('user_contactmethods', 'modify_contact_methods'); The above seems ideal for adding text input under the contact area of the profile. I'm also curious how I can add a text area or checkboxes to a user's profile? Additionally, is there a way to add tags from the blog as a field in the user profile? Ideally, I'd have a field labeled "Specialties" or "Areas of Expertise" which would be blog tags. And when the tags are used on the front end, this particular user's profile will show up among those results.
This is a great plugin that allows you to easily add custom fields to Users (among other things). < This tutorial will help you retrieve the values from user: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "users" }
Which hooks is this? add_action('wp', I have seen it here: `wp_schedule_event` Code snippet: add_action( 'wp', 'prefix_setup_schedule' ); I couldn't find this hook anywhere in documentation, how does it work?
The hook is described on this page in Action reference section.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "hooks" }
How to put custom admin setting field into a shortcode I set up an admin settings menu and I'd like to output the fields as a short code. The way I learned to output the fields from a tutorial was with: <?php $input_examples = get_option('sandbox_theme_input_examples'); ?> <?php echo sanitize_text_field( $input_examples[ 'textarea_example' ] ); ?> But putting that into the shortcode doesn't work: function shortcode() { return '<?php $input_examples = get_option('sandbox_theme_input_examples'); ?>'; return '<?php echo sanitize_text_field( $input_examples[ 'textarea_example' ] ); ?>'; } add_shortcode('shortcode', 'shortcode'); I'm guessing there is a specific way to put php code into the shortcodes that I'm not understanding? I've looked all over and can't find a solution to this.
Your issues aren't shortcode-related, just some PHP syntax problems. I suggest enabling debugging so you can see PHP errors being generated. Opening `<?php` and closing `?>` php tags are for switching between html and php output. See escaping from html in PHP documentation. A function can only `return` once, as it immediately ends execution and exits the function. See `return` in PHP docs. It also couldn't hurt to familiarize yourself with strings and the proper use of single and double quotes. function shortcode() { $input_examples = get_option('sandbox_theme_input_examples'); return '<img src="' . sanitize_text_field( $input_examples[ 'textarea_example' ] ) . '">'; } add_shortcode('shortcode', 'shortcode');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "shortcode, admin menu" }
using wp_tag_cloud with custom taxonomy I'm building a site for an architect and each Project page has a custom taxonomy called Project Services where the client can add various tags. I want to display them in a tag cloud so I'm using this: <?php wp_tag_cloud( array( 'taxonomy' => 'project_services', 'separator' => ', ') ); ?> But - the problem is that on each Project page, it's displaying _all_ the various Project Services tags in the database, instead of on a per page basis. Any ideas?
Is the normal behavior of `wp_tag_cloud`: it show all tags, not only the tags for a specific post, even if inserted in a singular page. However, that function has an option **include** that let you define the tags to include (must be comma separed list of tag ids). So, in your template file, pass that param to `wp_tag_cloud` using as value the list of tag ids of current post, that you can retrieve using `get_the_terms` and `wp_list_pluck` global $post; $terms = get_the_terms( $post->ID, 'project_services' ); $tag_list = implode(',', wp_list_pluck($terms, 'term_id') ); $args = array( 'taxonomy' => 'project_services', 'separator' => ', ', 'include' => $tag_list ); wp_tag_cloud( $args ); In this way only page related tags will be shown in tag cloud.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom taxonomy" }
Submitting form in wordpress plugin I am new to wordpress and currently making a plugin. I am getting list of authors using <?php wp_dropdown_users(array('name' => 'author'));?> Now when submitting my form I want to retain the current value entered by the user but as soon I submit the form the values get back to the default ones. I have searched on net and tryed alot but somehow not able to do this task.
Reviewing `wp_dropdown_users()` there is apparently a `'selected'` parameter. So in theory, you could probably pass the posted value in here. // set to the posted value, but you might be able to do this differently, depending on how you are storing the data $selected = isset($_POST['author']) ? $_POST['author'] : false; $args = array( 'name' => 'author', 'selected' => $selected ); wp_dropdown_user( $args );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "html, forms, plugins" }
Handle regular expression based redirects without .htaccess Is there a way to add a pattern of redirects to wordpress from a plugin? I'm using a host that sets up wordpress for me and doesn't give me access to the file system, so I can't edit the .htaccess file. I've found lots of plugins that allow you to list URLs that you want to redirect, but I haven't found any that let you insert patterns based on regular expressions. Specifically, I have an "events calendar" plugin installed that had a page of events for each day (whether or not that day actually had any events). A later release of that plugin, took those pages away. Now they are all 404, when I would like to redirect them to the main events page. They are all of the format: * /events/2017-08-29/ * /events/2017-08-23/ * /events/2017-08-19/ * ... (thousands more) How do I put in a single redirect rule for all of them?
Oleg's comment made me think that I might be able to find a plugin that would allow me to edit the `.htaccess` file. I installed the WP htaccess editor plugin. and was able to edit the `.htaccess` file despite not having shell or ftp access to the file system. I insterted the following line at the beginning of the htaccess file: RedirectMatch 301 ^/events/[0-9]{4}-[0-9]{2}-[0-9]{2}/$ Now my pages are redirecting properly instead of showing 404 status.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "redirect" }
How to detect that site is hosted on WPEngine? Is there anyway to detect that WordPress is hosted on WPEngine? The reason why I need to know it in their approach to eliminate cookies. But my plugin relies on cookie and can't work without it. So I need to not run the plugin on WPEngine hosting. Any thoughts?
From a quick look at wpengines headers it looks like there may be some info you can check. Your best bet is to get access to an account and dump out `$_SERVER` to see what's in there. For example it looks like `$_SERVER['SERVER_NAME'] = 'WP Engine/4.0'`. or perhaps `$_SERVER['HTTP_HOST']`. As per the comments below it also seems the `wp-config.php` on wpengine defines some custom constants you could check, for example `WPE_APIKEY` , `WPE_ISP`. Of course the problem is this can change at anytime outside your control. ### Updated: There is another workaround to figure out whether WPEngine is used. WPEngine uses its own MU plugin, which contains `WPE_API` class. By checking whether this class exists, we can say whether the plugin is hosted on WPEngine hosting or not. if ( class_exists( 'WPE_API', false ) ) { // is WPEngine hosting } else { // is not WPEngine hosting }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "hosting, cookies" }
Add-action in function How can i get add_action to work in a function, I want to hide a few admin menu item but not make the user and editor. function my_remove_menu_pages() { remove_menu_page('tools.php'); remove_menu_page('themes.php'); remove_menu_page('options-general.php'); remove_menu_page('plugins.php'); } add_action('admin_init', 'check_username'); function check_username() { $user = wp_get_current_user(); if($user && isset($user->user_email) && '[email protected]' == $user->user_email) { add_action( 'admin_menu', 'my_remove_menu_pages' ); } }
You can simply remove those menu items in your `check_username` method. add_action('admin_init', 'check_username'); function check_username() { $user = wp_get_current_user(); if( $user && isset($user->user_email) && '[email protected]' == $user->user_email ) { remove_menu_page('tools.php'); remove_menu_page('themes.php'); remove_menu_page('options-general.php'); remove_menu_page('plugins.php'); } } Your code doesn't work, because the `admin_init` action is invoked after `admin_menu`. Please see the Action reference page in WordPress Codex.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "actions" }
Leveraging Wordpress Comments on Custom Plugin Object page I have written a plugin that creates it's own tables to house the necessary schema for client's product. Then I created a single page that retrieves the custom object via passed in query string like so: Where it would retrieve the item with ID 7 in it's custom table. However the client would like to have commenting enabled on their custom object's page, with those comments obviously being related to the item with id 7. Seeings how I don't create a page, or post for this object. **Is there any way to tie Wordpress Built In Commenting to this custom object ?**
I would enable comments for that page and save them with a comment meta holding your object's ID. To be more specific, this is how would I tackle this issue: 1. Hook into `comment_post` action and save a comment meta called `my_object_id` with your custom object ID as a value when posting a comment from the relevant page. 2. To display only relevant comments, I'd query the comments with `meta_key => "my_object_id"` and `meta_value` set to the actual object ID you're retrieving the comments for.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "plugins, customization, comments" }
How to display custom user meta from registration in backend? I'm considering using the hooks for the WordPress registration form to add some custom fields: < My question is, if it's even possible, how do I display some of these custom fields in the backend Users > All Users? For example if I have fields for 'zip code' and 'address', how would I display this data in the backend? Thanks.
Actually I found this to be more strait forward and simpler: //add columns to User panel list page function add_user_columns($column) { $column['address'] = 'Street Address'; $column['zipcode'] = 'Zip Code'; return $column; } add_filter( 'manage_users_columns', 'add_user_columns' ); //add the data function add_user_column_data( $val, $column_name, $user_id ) { $user = get_userdata($user_id); switch ($column_name) { case 'address' : return $user->address; break; default: } return; } add_filter( 'manage_users_custom_column', 'add_user_column_data', 10, 3 ); More info for hooks for custom columns can be found here: <
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "users, user meta, user registration" }
Running a Gallery Shortcode in a Custom Fields Widget I am creating a website for a Fringe Adelaide Venue, we have planned on displaying a gallery on each artist page. We are already using Custom Fields to place some unique content in a Custom Fields widget that we are including on the page. We have tried to place and execute the gallery shortcode inside of the Custom Fields widget, with no success. We need it to be in the widget so we can position it properly. The theme is Gantry, I am able to change plugins if necessary, but not theme. I have spent all day yesterday researching a solution and still have not succeeded. EDIT: The Widget we are using for Custom Fields is Custom Field Widget Cheers, Thomas
You can try to add this filter <?php /** * Plugin Name: Shortcodes support for the Custom Fields Widget plugin * */ add_filter( 'custom_field_value', 'do_shortcode' ); as a plugin. This should hopefully make your shortcodes work. Here you can read more about the WordPress function `do_shortcode()`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field, widgets, shortcode, plugin nextgen gallery" }
Change the footer text on the login page I am customising the login page and would like to alter the footer text that takes the user back to the website. Ideally and as an example, changing it from the first image, to the second just below: 1. !enter image description here 2. !enter image description here I've searched around a bit but can't seem to find the answer I'm looking for in modifying the text. The closest I have is changing the _Register_ or _Lost your password?_ text, but can't apply this script to the third user option. **functions.php:** function back_to_site_text( $translated ) { $translated = str_ireplace( '← Back to My Site', 'Head back to My Site', $translated ); return $translated; } add_filter('gettext', 'back_to_site_text'); add_filter('ngettext', 'back_to_site_text'); How do I change the footer text on the login page that takes the user back to the main website?
You have the wrong values , you can't use `←` , instead use the right encoding which in that case is `&larr;` and also `%s` for the title. Also you only want this to run on two pages. function back_to_site_text( $translated ) { if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) $translated = str_ireplace( '&larr; Back to %s', 'Head back to My Site', $translated ); return $translated; } add_filter('gettext', 'back_to_site_text');
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "php, functions, filters, hooks, login" }
Check if add_menu_page exists or not I'm working on a plugin that I have to release in parts. The problem is, if there is a menu in the page then add the new plugin to the 2nd or next submenu else add a new menu and then add the plugin to 1st submenu. My questions: 1. How to check that there exists a menu? 2. If I'm coding a reusable function , that will go with every plugin then that causes conflict option. 3. I don't know the order of the plugin release. add_menu_page( 'Page Title', 'Top Menu Title', 'manage_options', 'my_unique_slug', 'my_magic_function' ); add_submenu_page( 'my_unique_slug', 'page title', 'submenu title', 'manage_options', 'my_submenu_slug', 'my_magic_function_of_submenu' );
You can use the fourth parameter of `add_menu_page()`, the `my_unique_slug`, to check if the page exists: if ( empty ( $GLOBALS['admin_page_hooks']['my_unique_slug'] ) ) add_menu_page( 'Page Title', 'Top Menu Title', 'manage_options', 'my_unique_slug', 'my_magic_function' ); `$GLOBALS['admin_page_hooks']` is the list of registered pages.
stackexchange-wordpress
{ "answer_score": 23, "question_score": 12, "tags": "plugins, menus, add submenu page" }
Override default options in plugin metaboxes Imagine you are on a post-new page to add a post, and a metabox added by a plugin has a lot of checkboxes that always need to be checked manually. Here is one of them: <div class="form_item form_item_checkbox form_item_plainview_form2_inputs_checkboxes_blogs_5 "> <input class="checkbox" id="plainview_form2_inputs_checkboxes_blogs_5" name="broadcast[blogs][blogs_5]" type="checkbox" value="5"> <label for="plainview_form2_inputs_checkboxes_blogs_5">Some item I need to be checked by default</label> </div> I´d like to have this checked by default every time the page is loaded. I don't want to modify the plugin code. I suppose a jquery would be the most flexible way to approach this problem. Any advice on it?
as example of js code that will run on every new post page function admin_footer_se_119285(){ ?> jQuery(window).ready(function(){ if (jQuery('#metabox-id-div').length == 1){ // put your code } }) <?php } ?> Take a look to usefull reference to admin_footer-(plugin_page) action hook
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, metabox, wp admin" }
Pass boolean value in shortcode In WordPress shortcodes, how can I pass boolean attributes? Both of `[shortcode boolean_attribute="true"]` or `[shortcode boolean_attribute=true]` are giving string values. EDIT There would be no problem for users who know what they're doing if I use the trick which was commented by @brasofilo. But some users will get lost if they give an attribute `false` value and receive `true` value. So is there any other solution?
Is easy to use `0` and `1` values and then typecasting inside the function: `[shortcode boolean_attribute='1']` or `[shortcode boolean_attribute='0']` but if you want you can also strictly check for `'false'` and assign it to boolean, in this way you can also use: `[shortcode boolean_attribute='false']` or `[shortcode boolean_attribute='true']` Then: add_shortcode( 'shortcode', 'shortcode_cb' ); function shortcode_cb( $atts ) { extract( shortcode_atts( array( 'boolean_attribute' => 1 ), $atts ) ); if ( $boolean_attribute === 'false' ) $boolean_attribute = false; // just to be sure... $boolean_attribute = (bool) $boolean_attribute; }
stackexchange-wordpress
{ "answer_score": 16, "question_score": 21, "tags": "shortcode, customization" }
How to remove/hide Yoast's "SEO" tab in admin panel? I don't want this shown to members who register for my website as it's confusing and irrelevant for them. I assume some code added to `functions.php` will do the trick but what code?
This _should_ hide it for everyone but the admin. If you run into any issues, you can use a plugin like Advanced Access Manager to get the job done. With that you will have more control of what each user level has access to. function hide_yoastseo() { if ( !current_user_can( 'administrator' ) ) : remove_action('admin_bar_menu', 'wpseo_admin_bar_menu',95); remove_menu_page('wpseo_dashboard'); endif; } add_action( 'admin_init', 'hide_yoastseo');
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "plugins, admin, plugin wp seo yoast" }
wp-login.php not returning error messages / or gives 404 I have several WP sites that were logging in fine last week. Now today thay are all failing to login using the native wp-login.php. The strange thing is some of the sites have the "Woocommerce" plugin installed, using the plugin login form I can access the dashboard. But not using wp-login.php I have already tried: * adding this to wp-config.php /** wp-admin login fix */ define('ADMIN_COOKIE_PATH', '/'); * re-uploading all wp files apart from wp-content * Changing file permissions of wp-login.php * permalinks on and off * removed .htaccess * Disabled Plugins * 100% fresh install of WP 3.6.1 on a new DB The thing that is confusing me is that I can still login using woocommerce on sites that have it. And the native login was working last week. Could this be a hosting issue? Any help / suggestions would be very much appreciated. Thanks in advance Joe
Ok the problem has gone. As strangely as it appeared it vanished. I got a call form a client later that day I asked them if they could login, yes they could. I then tried logging in through my phone this was also successful. So the problem seemed to be localised to my computer. I logged in the next day and all was fine. I still don't know what caused the error but its gone now. Cheers for the comment anyway @birgire
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp login form" }
Use theme folder instead of plugins_url I imagine this is really simple but I can't work it out. I am trying to add a menu page to the WordPress dashboard through my theme. I have the following... add_menu_page( 'Test', 'Test', 'manage_options', 'myplugin/myplugin-admin.php', '', plugins_url( 'myplugin/image/icon.png' ), 6 ); Which works, but I want to use an icon in my themes directory instead of plugin. How can I alter this to look in there instead? I have tried using `theme_url` instead but it's not working.
There is not such a function as `theme_url`, if I am not mistaken. Take look at `get_template_directory_uri` or `get_stylesheet_directory_uri`
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "theme development" }
Admin Dashboard - Recent Comments source I need to see the source file for the admin dashboard widget that shows recent comments, can anyone point me to the exact php file that does this? I can't find it anywhere on the codex or in google searches. Thanks
It’s located under `wp-admin/includes/dashboard.php` on line 612 and the function which calls the widget is `wp_dashboard_recent_comments()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "comments, admin, dashboard" }
Insert images into wordpress post with a query I have a Wordpress installation with 2.000 posts. Also in a separate table of my database I have a set of image paths and the filenames of the images, each image is assigned to each post of my Wordpress installation based on the post id. eg of my images' table id|image -------- 1 | img1.png 2 | secondimage.jpg ... 2014| onemoreimage.gif Is it possible to execute an SQL query or a Wordpress API call to insert each image as featured image of each post based on the ID? Also where should I upload the original image files? Thanks in advance
Yes, it is possible, WordPress does not have an API, but some useful functions. I would load all your rows into array like $your_table = ['post_id' => 'image', 'post_id' => 'image', …] Then execute a foreach loop foreach($your_table as $post_id => $image) { //full path to the image $image_path = _YOUR_FULL_ABSOLUTE_PATH.$image; /** * Get an ID of the inserted attachment * This takes care of resizing image and stuff… * The fourth param I would sugest you to keep true, since in case of duplicate entry in your table, it will not have been inserted more than once */ $featured_image = wp_insert_attachment(array('attachment_meta'), $image_path, $post_id, true); //assign featured image add_post_meta($post_id, '_thumbnail_id', $featured_image); } 'attachment_meta' study `here`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, images, query" }
What are the disadvantages of using global variable? I am a newbie at WordPress. In my "recent posts" shortcode, I used `global $post` variable, because `the_title()` function was giving me page's title, not post's title. I am not exactly sure, but I thought that's because of loop inside of a loop. Some advanced users here tell me not to use `global` variable, so using `global $post` variable inside my "recent posts" shortcode is good or not?
The `global` variable `$post` will be set to the first post in the main query. When any Loop runs (assuming it is constructed correctly), whether the main Loop or any number of secondary ones, `$post` will be set to each post in that/those loops in turn. At the end of the Loop, it will be set to the the last post in the last Loop that ran. The functions `wp_reset_query` and `wp_rest_postdata` help clear this up in a lot of cases. I am pretty sure that the problem is the construction of your "loop inside of a loop" but you don't post the code so guessing is all I can do. My guess is that you have something like: $recent = get_posts(/*...*/); foreach ($recent as $r) { the_title(); } And you need: $recent = new WP_Query(/*...*/); if ($recent->have_posts()) { while($recent->have_posts()) { $recent->the_post(); the_title(); } } wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "loop, shortcode, globals" }
Tracking Disqus comments on Google Analytics I'm using Disqus for my blog comments, and Google Analytics for tracking users. I have both implemented using plugins (Disqus Comment System and Google Analyticator). I'd like to track comments, but I can't figure out how to do that. I have researched the problem, and there's some documentation for it, but it's not very clear. So far I've found some help from Disqus themselves (here), and from On Digital (here), so now I know what code to add. What they don't mention is where to add it. Do I insert it in one of the Disqus plugin files? My theme? Which file, and where?
You can use that snippet just anywhere where it can be rendered on single pages. For example, you can paste this under functions.php of your theme: function hook_disqus_config(){ if( ! is_singular() ) return; ?> <script type="text/javascript"> function disqus_config() { this.callbacks.onNewComment = [function(comment) { _gaq.push(['_trackEvent', 'Disqus', 'New Comment', comment.id]); }]; } </script> <?php } add_action( 'wp_footer', 'hook_disqus_config' ); Disqus should do the rest.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, google analytics, disqus" }
Inserting above the comment template I want to insert content, just above the comment template.I have tried all the word-press filters and hooks but failed. I want to insert the content above the comment template, I mean above all comments. Thanks EDIT function my_fields() { echo '<p>action/p>'; } add_action('comment_notes_before','my_fields'); Please see the image-I want to insert content in color part of the image in single.php !enter image description here
It mainly depends on a theme, whether there is a hook, in which you can call an action. **Simple ways, how to do that:** 1. You insert your code directly into `single.php`, right above the code calling `comments_template()`, 2. You create a hook (e.g. above comments_template()) as `do_action('my_hook')` and then you hook into it your function `add_action('my_hook', 'function_i_want_to_hook')` 3. Or you do the same as steps above, however, working with file, where comments template code resides, i.e. `comments.php`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, filters, hooks" }
Get post object in shortcode function I have to display a post from another page (index.php), so my code is $section_id = 16; $section_home = get_post($section_id); setup_postdata( $section_home ); the_content(); This post (with ID 16) has a few shortcodes inside. I can't access the $post object inside of the shortcode functions, for example I tried function tp_sc_flipcoin($atts,$content = null){ global $post; var_dump($post); return ""; } add_shortcode( 'tp_flipcoin', 'tp_sc_flipcoin' ); and it displays the post with ID=1, I also tried: function tp_sc_flipcoin($atts,$content = null){ var_dump($post); return ""; } add_shortcode( 'tp_flipcoin', 'tp_sc_flipcoin' ); and in this case it displays NULL. What am I doing wrong?
You need to reassign the $post yourself. See the WordPress Codex that `setup_postdata` won't do it for you. Try this: global $post; $section_id = 16; $post = get_post( $section_id ); setup_postdata( $post ); the_content();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "shortcode" }
RSS feed url showing page not found. How to solve it? Am developing a WordPress site. My site footer having a link to navigate RSS Feed URL. This URL is generated using `<?php bloginfo('rss2_url'); ?>` and it correctly generating the URL like `mysite.com/?feed=rss2` but this link is not working from home page. Showing page not found when i try to access it from home page. But When i try to access it from category page the link is working. Please help me to solve this issue. Thank you. Hariprasad **Update** Am not using default category or post of wordpress. Only using custom post type and custom taxonomies.
Solved it I think the custom post types does not display in feed by default. It worked when i add following code in function.php //enabling feeds for custom post types.. function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('news', 'results', 'events', 'video-gallery'); return $qv; } add_filter('request', 'myfeed_request'); Thanks
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, themes, rss, feed" }
Div around YouTube video My posts have YouTube embedded videos in the form of: <object width="600" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" name="src" value=" /><embed width="600" height="400" type="application/x-shockwave-flash" src=" /></object> How do I wrap a `<div>` around it? I've tried adding the following to the `functions.php` file: add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4); function my_embed_oembed_html($html, $url, $attr, $post_id) { return '<div id="video">' . $html . '</div>'; } It doesn't work. What do I do?
I'm not sure why that's not working except maybe you need to put the returned stuff in a variable? This is what works for me when I put it in my functions.php file: add_filter( 'embed_oembed_html', 'tdd_oembed_filter', 10, 4 ) ; function tdd_oembed_filter($html, $url, $attr, $post_ID) { $return = '<figure class="video-container">'.$html.'</figure>'; return $return; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "embed, youtube, oembed" }
Advanced searching form I am trying to create an advanced searching page on front-end page for users. I have been trying to find but it's not easy to find some tutorial or sample source. I have found that It is possible to put some filters on admin panel. I am looking for just like this for front-end for users. See this tutorial for admin panel I need to create like this on front-end for users. this is custom post-type searching. Any tips? tutorial, sample codes? Thanks for your time and good weekend ;)
WP Advanced Search is exactly what you're looking for. They have a very good documentation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "forms" }
How to redirect homepage to actual URL? I have a stupid problem. In the custom header template I include on all pages are some images. When I set the links to the images as images/image.png it works on the homepage but not on other pages. When I set the links to these images as **../** images/image.png it works on all other pages but not on the homepage.. This is because the homepage url is given as 'mysite.com' instead of 'mysite.com/home/'. Is there any easy solution to this problem? My guess was to redirect any visit to the homepage to 'mysite.com/home/'. But it looks like Wordpress itself prevents this. If I type 'mysite.com/home/' in an adress bar it redirects immediately to 'mysite.com'. I had no idea that changing these image links would give me such a weird problem :) I hope anyone here has a solution for it. Thx in advance!
Don't use relative paths in WordPress, put the images in your theme directory and use the API to output correct paths. <img src="<?php echo get_template_directory_uri(); ?>/images/image.jpg">
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "images, redirect, urls" }
How do I change the value of lang=en-US I have noticed that in the `<html>` tag on my WP site that the language is defined as US English. <html lang="en-US" prefix="og: I would like to change it to British English `en-GB` but I'm not sure of the best way. I dug around and found `language_attributes()` in `general-template.php` which makes a call to `get_bloginfo('language')`. I could manually insert the value here but that doesn't seem like the best way to do it. What is the proper way to change this value?
The value for that string is normally taken from the option `WPLANG` in your database table `$prefix_options`. You can set it in the backend under _Settings/General_ (`wp-admin/options-general.php`) or per SQL. There several ways to change that value per PHP: 1. Create a global variable `$locale` in your `wp-config.php`: $locale = 'en_GB'; 2. Declare the constant `WPLANG` in your `wp-config.php`: define( 'WPLANG', 'en_GB' ); This has been deprecated, but it'll still work. 3. Filter `locale`: add_filter( 'locale', function() { return 'en_GB'; }); This a very flexible way, because you can add more conditions to that function, for example check the current site ID in a multisite.
stackexchange-wordpress
{ "answer_score": 13, "question_score": 8, "tags": "html, language" }
Is there any simple wordpress search template that works with existing searchforms? I want to replace my theme's search functionality with new functionality that searches trough text widgets. Almost all content of my site is provided trough text widgets (they are static pages). Is there any default wordpress search template that I can use and that will work with my existing search forms? In regards to Toscho's questions asked here: 1. My site doesn't have that much content, so slowness is not a problem. 2. Search results may point to a specific page, the page that hosts the widget 3. I want only to display results from text widgets.
Widget content is stored in the `$wpdb->options` table as serialized data. You can search that with SQL because to SQL serialized data is just a string. SELECT option_value FROM {$wpdb->options} WHERE meta_value LIKE "something" But... * The table is not indexed for that kind of search * Searching serialized data is dicey anyway * And I have no idea how you are going to associate the widgets with the pages. That does no happen by default and you have not answered my question about that point. Put together you aren't going to have a very efficient query and once you jump through hoops to associate the widgets and pages/posts it is going to be even less efficient still. Sorry, but the decision to build the site the way you have was badly flawed.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, templates, search" }
Is there a way to call on just the content of a Page without actually using that Page? The question sounds weird i know, but what i'm trying to do is add a gravity form into a template that i made. But all of their tutorials seem to be more along the lines of adding a form to a page and not so much to a template. So the idea was to use a get_content() from a specific Page that i created (called "Form" in this case) put that into it's own content-form.php file and then call a get_template_part() into the section of my template where i need it in. First off, is this too much abstraction? If it's just better to somehow call the form from this specific Form Page into my template of choice i'll do that but i'm just not sure how to go about this. Thanks.
You can just put something like the following into your template file where you want the form to appear (example of a form called Contact Us): gravity_form('Contact Us', false, false, false, '', false); For more info on the false etc, see here: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin gravity forms, get template part" }
How to get the excerpt of a page before more tag? I have many pages in my wp installation. All I want is to be able to display the excerpt of any page, also on any page (before more tag). How do I go about it? I was fetching the content of the current (front) page through this code: global $more; $temp = $more; $more = false; echo get_the_content( '' ); $more = $temp; (I use these lines in my front page template) But I have no idea of how do I fetch the content of any page. Maybe I need to do manipulations with add~/remove_filter changing the page id/slug/title/etc?
The content is manipulated by the `get_the_content` function, and that function always assumes the current post in the Loop. You can't pass it an ID, strangely. The easiest way to get just the bit before the more for an arbitrary post ID is: $p = get_post(1); $p = preg_split( '/<!--more(.*?)?-->/', $p->post_content ); echo $p[0]; There may be ways to hijack the `global` `$post` variable but unless you really need the complex manipulation of `get_the_content` I wouldn't bother. You can always create a near clone of that function that will allow you to pass an ID into it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pages, tags, excerpt, read more" }
How can I edit the content in index.php? I want the start page to be editable from a template. At the moment I can only edit the content by directly editing the HTML. Setup: * Settings » Read » "Front page displays Your latest posts" * The template that shows in the startpage is `index.php` I want to be able to create a page edited from the Pages list that will show as the start page. I've tried to create a new page called MyStartPage. Set its template to Startpage (`index.php`). I've tried setting Settings » Read » Front Page displays Static page MyStartPage I've made sure the `index.php` has The Loop that makes the calls to get Title and Content as is working in other templates.
If you are editing a theme or you are having a child theme, You can make your own custom template, give it a name Include header and footer in it using <?php /** * Template Name: Home Page * * Home page Layout */ get_header(); ?> <!-- Do whateveer you want here --> get_footer(); ?> When you create a page in backend you'll get an option to select the template for the page i.e Home Page, assign the template you just created !Home Page Template and set this page as home page from settings.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, templates" }
How can I attach a gallery to a post with a short code? I would like to attach an image gallery to a post. Here how i am trying to do it: * from the posts administration page i click on: add new media -> create gallery * Select the images and click to: create new gallery After that i dont have a button: "Save gallery", i have just "insert gallery", but this add the shortcode to the content of my post. I would like to include the gallery like an "object" in my template using wordpress API. If i remove the shortcode from the post content i loose completely my gallery... Is there a way so?
The gallery **_is_** the shortcode. It is not, so far as I know, saved in any other place or in any other way than in that shortcode. You can print/process shortcodes anywhere you want with tricks like this: echo do_shortcode('[gallery option1="value1"]'); Or this: $gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]'; print apply_filters( 'the_content', $gallery_shortcode ); Both from the Codex. You can see in the source how that gallery is constructed. It is actually parsed from the values passed in the shortcode. If you need to save that shortcode and retrieve it some other way you will need to construct your own mechanism for doing so.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "gallery" }
Why does is_front_page and is_home always return true for posts in wordpress? My front page is just a list of the posts separated by category. I'm working on a plugin that get the id of the post but needs to test if the user is currently on the front page: if(is_front_page()){ do this thing } else { do this other thing } problem is, on the post pages it returns true for is_front_page. I tried is_home but get the same result. I have the home in admin set to "latest posts" (not a static page) and displaying the posts on the main page via loop-home. I'm using is_home in the header and getting the correct response.
Turns out since the plugin output in the footer I just had to reset the query: wp_reset_query();
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, homepage" }
How can a left and right margin be added to the admin bar without access to "...wp-includes/admin-bar.php"? I do not have access to _"wp-includes/admin-bar.php"_ due to security restrictions placed by my host, they have advised me to use css stylesheets which I am not familiar with. I am looking to add a left and right sided margin to the links (login/register/sign out etc) in the admin bar so they align with the main content and display correctly on mobile devices. How can this be achieved?
If you are using firefox, chrome or safari to browse your site, you can inspect each page's elements. For example in chrome you can right click anywhere on your browser window and select "inspect element". Now you should be able to see the code for that page and find out the css classes that the admin bar uses. For example: <div id="wpadminbar" class="" role="navigation"> </div> Once you know what classes to target with css, you can edit your style.css to change those elements. You will need to have some basic css skills. You will also need to use the attribute "!important" in your css to make sure it's overriding the default wordpress css.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "css, admin menu, admin bar" }
paginate_links and query vars I have using the Wordpress `paginate_links()` to build a paginator on a custom archive template for a custom post type. My site uses permalinks: <?php echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'current' => max(1, get_query_var('paged')), 'format' => 'page/%#%', 'total' => $wp_query->max_num_pages, )); ?> This works fine until I try to add query string vars to build a custom search string when the paginator echoes: .../entries?post_type=entry&s=testpage/1 .../entries?post_type=entry&s=testpage/2 Instead of: .../entries/page/1?post_type=entry&s=test .../entries/page/2?post_type=entry&s=test and so on... How can I get the correctly formatted URLs?
Seems that the query string is coming from the base argument call to `get_pagenum_link()` so I have removed the query string component and re-add it with 'add_args'. Like so: <?php echo paginate_links(array( 'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%', 'current' => max(1, get_query_var('paged')), 'format' => 'page/%#%', 'total' => $wp_query->max_num_pages, 'add_args' => array( 's' => get_query_var('s'), 'post_type' => get_query_var('post_type'), ) )); ?>
stackexchange-wordpress
{ "answer_score": 9, "question_score": 3, "tags": "paginate links" }
How to show author's avatar in the post meta data with plugin `user-avatar` I'm using `user-avatar`, and I want to show user icon in the post meta data. < I'm writing like this. ` <?php the_author_posts_link(); ?> <?php echo get_avatar(); ?> ` It shows only default "nobody" avatar. If I write like `<?php echo get_avatar("[email protected]"); ?>`, then it shows my avatar through `user-avatar` plugin. So if I can get the author's emails, it works all fine. I tried to get the email by `<?php the_author_meta('user_email'); ?>`. But it doesn't return the email, but it outputs directly. I'm stuck now. How can I set user avatar in post meta area?
Use `get_the_author_meta()`, this function returns data, it doesn't display it. For example:-- <?php $user_email = get_the_author_meta('user_email'); ?> For more information check it in the codex
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, author" }
Unable to access wordpress login.php I has been completed a theme for a client. I Used to access the live wp-admin page using **< But that page shows just a blank(white) page. How to get fix that? Note: Their hosting provider is supporting wordpress. The error now generating is: Parse error: syntax error, unexpected '?>' in /home/mysitee/public_html/mytheme/wp-content/themes/theme name/include/widget.php on line 1
What does the content of `theme name/include/widget.php` ? The error is pointing to line 1 and telling you it did not expect to see `?>` there. My guess (without seeing the file) is you have closed a php tag instead of opened it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "themes, publish, ftp" }
Comments from mobile apps & Disqus I'm currently using Disqus in my WordPress Installation, and I am pretty happy with it. However, I'd like to extend my native mobile app (Windows Phone) to allow the users to post comments directly inside the app. I'm using a framework which supports WordPress comments for registered users out of the box, and I wouldn't want to rewrite the app to explicitly support Disqus. But as far as I know I can't combine both systems without problems, right? I'm certainly not the only person with that problem, so what's your strategy? Should I switch to Jetpack comments? I don't want to loose social login options, at least on the normal homepage. WordPress Version 3.6.1 Disqus Comment System Version 2.74 < Jetpack
There's a pre-release Windows Phone SDK right now for Disqus, and you might want to sign up and try that out: < Generally speaking it's not difficult to sync up discussion threads between a mobile app and a Wordpress site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments, mobile, disqus" }
arguments for comment_notification_text filter From WP codex: > comment_moderation_text: applied to the body of the mail message before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail body text, comment ID. Nevertheless, when I put in my functions.php: function x99($textMsg, $comId) { if (is_null($comId)) { return "empty"; } else { return ($textMsg); } } add_filter("comment_notification_text", "x99"); the notification message body is "empty". So comment ID is null. Why? How can I retrieve it?
For the arguments, check the source: $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id ); You have two parameters. The first is the notification text itself, prior modification by your filter. It is constructed earlier in the same function and is different for comments, trackbacks, and pingbacks. The second parameter, as you might guess from the name, is the comment ID. That is all correct, as per the Codex entry you found. However, your problem is that only the first parameter is passed by default. If you want any of the others you have to ask for them by means of the _fourth_ parameter of `add_filter`. add_filter("comment_notification_text", "x99", 1, 2); The third parameter is a priority. You can raise that or lower it depending on your needs. `1` should run your filter early.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters, email, notifications" }
Register Taxonomy - What is `query_var`? The Codex doesn't really explain it very well, what is it used for and how do I use it exactly?
It is explained pretty thoroughly in the Codex, in my opinion. It serves a purpose e.g. when you want to grab posts for your taxonomy, it is a URL slug for your taxonomy, e.g. `example.com/tag/cats` -> `example.com/query_var/cats`. > Note: The query_var is used for direct queries through `WP_Query` like new WP_Query( array( 'people' => $person_name ) ) > and URL queries like `/?people=$person_name`. Setting `query_var` to `false` will disable these methods, but you can still fetch posts with an explicit `WP_Query` taxonomy query like WP_Query(array('taxonomy'=>'people', 'term'=>$person_name)). Basically, `query_var` is part of the WordPress Query Vars.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, register taxonomy" }
Alternative to file_get_contents() for theme operations My theme options page needs to write to the style.css file in order to store updated theme settings. To do that, I'm using file_get_contents() and file_put_contents() However, theme-check plugin complains about it. What is an acceptable alternative for writing to local files?
Short answer, but adequate I think. While I have not tested this, I doubt that there would be a problem if you used the Filesystem API provided by the Core.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, filesystem" }
Disqus resetting comment count to 0 For some reason my Disqus comment system seems to resetting the comment counts to 0 on the main page. If you load my site the current blog at the top has 1 comment, you can see it says 1 very briefly then changes to 0. Refresh the page and keep an eye out for it if you miss it. I have no idea why it's doing this. If you click the blog to read it, the comment count correctly displays 1. Also, the 3rd blog down regarding VPNs, reads 0 comments on the main page and 0 comments when you click on it, even though it has a comment. Can anyone suggest a solution? _Edit_ Plugin link.
After some further investigation I found that removing and re-installing the plugin has no negative effect on existing comments and resolved the issue.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments, disqus" }
Disqus moderation page not working in WordPress admin section If I login to my Admin section and click Comments on the left, the Disqus moderation page does not load. On further inspection this is because it's trying to load the page over http:// and my blog is loaded via https:// so it is being stopped. Everything else loads via https:// but I don't know how/where to change this page to do so. Link to my site if you need it.
I had a response from Disqus Support regarding this issue: > Hi Scott, > > To clarify, the Disqus moderation panel in Wordpress is not intended to be used with https. If you would like to use the moderation panel in https you’ll need to go to the Disqus moderation panel directly at: < > > If you have any trouble or other questions, please let us know. > > Qarly > > Disqus Product Support
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments, disqus" }
Cite-Tag for blockquotes I want to have a cite underneath my blockquote, that has a certain style. "Blockquotes are an essential part of a fancy website." – Cite The markup should look like this: <blockquote><p>Blockquotes are an essential part of a fancy website."</p> <cite>Cite</cite></blockquote> But the WYSIWYG-Editor does not offer me the possibility to define a cite for the blockquote. And I can't force my users to write the HTML by hand. Is there a way to make the WYSIWYG-Editor generate the required markup?
The TinyMCE Custom Styles Codex Page should get you through this. There are code snippets on that page, but, as an overview, the process requires two steps: 1. Add the TinyMCE "styleselect" element to the first or second row of icons. 2. Add one or more elements to that styleselect menu. If this were me, I would consider also _removing_ the blockquote button from TinyMCE and then adding `blockquote` as an option in the styleselect along with `cite`. Doing it that way means your editors can find the correct markup for an entire `blockquote` in one place. And I hope this goes without saying, but make sure to implement a custom `editor-style.css` file so that the `blockquote` and `cite` styles match the theme output.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "tinymce, wysiwyg, html" }
Validating custom meta boxes with jQuery results in posts being saved as draft instead of published post I have a custom post type with a bunch of custom fields. I want to validate the meta box input with jQuery as soon as you press the Publish button. Here's what I have (I left out all my validation stuff): $("input#publish").click(function(e){ e.preventDefault(); $("#ajax-loading").show(); $('form#post').submit(); }); As you can see I am only interrupting the form submit at this point, nothing else going on. However, posts are now saved as drafts only and I can not manually set them to published (I have administrator priviliges). As soon as I remove above code, all is back to normal. Is there any way to get this type of client side validation working properly without using plugins? I'm on Wordpress 3.6.1.
So here's what I ended up doing: I hide the publish button, replace it with my own publish button (one that does not submit the form) and when you click that button the validation script is executed. When there are no errors, a click event is registered on the original publish button. That way, no more drafts and problem solved.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field, jquery, validation" }
Custom Post Type Archive in Sub Folder I have a sub-directory in my Wordpress theme (there are a lot of pages and I want a more logical structure). I have a custom post type called "entry" but if I place the archive-entry.php template in my sub-directory it is no longer picked up by the theme. Is there a way I can put my custom post type archive templates in a sub-directory?
Unlike page templates, WordPress doesn't look in subdirectories for post template pages. The base function used for locating such templates is `locate_template()` (see source), which looks in the root directory of your theme (and parent theme). _(On the other hand`get_page_templates()` searches sub-directory)_. You can use `template_include` filter (which filters the absolute path to your template) to change the template used: add_filter( 'template_include', 'wpse119820_use_different_template' ); function wpse119820_use_different_template( $template ){ if( is_post_type_archive( 'entry' ) ){ //"Entry" Post type archive. Find template in sub-dir. Look in child then parent theme if( $_template = locate_template( 'my-sub-dir/archive-entry.php' ) ){ //Template found, - use that $template = $_template; } } return $template; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "directory, custom post type archives" }
How to get author's name by author's id I want to show recent posts like this. <ul id="recent-posts"> <?php foreach( wp_get_recent_posts() as $recent ){ ?> <li> <a href="<?php echo get_permalink($recent['ID']); ?>"> <?php echo $recent["post_title"]; ?> by <?php echo $recent["post_author"]; ?> </a> </li> <?php } ?> </ul> But `$recent["post_author"]` returns only id of author. And this is outside `The Loop`, so I can't use `the_author()` function. How can I get author's name from ID? Or maybe there is a better way to do it?
Try `get_user_by()`: get_user_by( $field, $value ); In your case, you'd pass ID, and the user ID: // Get user object $recent_author = get_user_by( 'ID', $recent["post_author"] ); // Get user display name $author_display_name = $recent_author->display_name;
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "author" }
How to show 5 posts from specific category on related page? I'm not familiar enough with wordpress to ask the question directly, so please bare with me as I explain what I'm looking for. I have four primary sections of my business (A, B, C & D, for example). * each section has it's own page * each section also has a category with the same name * various pages and posts are categorized under each section I want an area in the sidebar (probably a widget) to show N (probably ~5) summaries of items categorized as A on page A. And the same on pages B, C & D. Remembering that I am a Drupal developer who does not know the Wordpress landscape very well, how would I go about this? Is there a ready-built widget or am I looking at something custom?
You can use this plugin < and use widget logic to display particular category posts < Please add is_page('A') in widget logic section Then select posts form category A in posts in sidebar
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, pages, widgets" }
How to redirect to cart page using wp_redirect I am trying to the redirect on a cart page using a bellow code but,I am not able to redirect on cart page . wp_redirect("'.home_url('cart').'");
Please use get_page_by_path wp_redirect( get_page_by_path( 'cart' ) ); exit(); Reference link for get page by path
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp redirect" }
How do I reference the front page's parent Page object? I have created a "News" Page and have switched my posts-page to that Page. Now Posts show up under that Page, as desired. The problem is I'm trying to access the core Page to pull out some information. On any other Page I could look to `$post` but in this setup, with blog posts being present, that variable is otherwise taken. How do I reference the underlying Page object?
You can get the ID of the front page via `get_option( 'page_on_front' )`. (See also: WordPress option reference.) From there, you can query the page object via `get_post()`: $frontpage = get_post( get_option( 'page_on_front' ) ); Then the content is in the `$frontpage` object: $content = $frontpage->post_content;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pages, frontpage" }
Multiple variables through wp_get_image_editor I want to merge 2 images with imagick. I already know how to merge them with imagick, but I need to pass 2 variables through `wp_get_image_editor` to get this to work. I named the 2 variables `$background` and `$logo`. `$background` contains the background image path. `$logo` contains the logo image path. Does anyone know how I should do this?
Mike Schroder said: "WP_Image_Editor is built to handle one file at a time, and there isn’t anything built in to combine two images by default. The main reason here is that the files in-memory aren’t compatible with one-another if different editors (say, GD and Imagick) are used for each. There are a few different ways to handle it, of course, but one way to solve the problem here would be to load one of the two images, then extend the Imagick editor (or both editors, if you prefer more compatibilty) to support combining images. Say, with a $image->combine( ‘filename’ ) method. First, you’d load one of the images with wp_get_image_editor() (and specify that ‘combine’ is a required method), then call your combine method while specifying the second image."
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "images" }
pingback returns faultCode 0, no message I have implemented my own pingback client and sent out pingbacks to different hosts. Some wordpress instances responded to the XML-RPC pingback request with a `faultCode` of `0` and an empty `faultMessage`. What can be the cause for that?
For some reason, the default filter attached to pingback errors, will not send an error message _unless_ the error code is 48. From `wp-includes/commment.php`: function xmlrpc_pingback_error( $ixr_error ) { if ( $ixr_error->code === 48 ) return $ixr_error; return new IXR_Error( 0, '' ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "pingbacks" }
Wordpress 3.6 Video shortcodes in template I understand the video shortcodes work fine when inserted into a post. Easy. What about when you want to have more control about where the video should be displayed. I would like to use something like: do_shortcode('[video webm=" width="640" height="360" autoplay="true" loop="true"]') or using the prebuilt WP function: wp_video_shortcode( array('webm'=>' ) Neither of these solutions seem to work. As anyone else managed to get this to work? Outside of the embedding it in a post scenario? Much Appreciated.
From the looks of it, you aren't `echo`-ing the `do_shortcode` function, which you should. Try this: <?php echo do_shortcode('[video webm=" width="640" height="360" autoplay="true" loop="true"]'); ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "videos" }
How can I find plugins' slug? I'm wondering how can I find plugins' slug (slug = internal name used by WordPress to do plugin updates and to determine which plugins are currently active)? It is usually plugin's folder name but if a plugin doesn't have a folder, it is its file name (like hello.php). Are there any other exceptions? 1. Do lowercase and uppercase characters matter? 2. Can a plugin have different slug than its folder name? What if there's a plugin called hello.php and another /hello.php/hello.php?
The string used in WordPress to identify the plugin is: plugin_basename($file); … where `$file` is a file with the plugin headers. So if you are in your plugin, get the slug with: $slug = plugin_basename( __FILE__ );
stackexchange-wordpress
{ "answer_score": 10, "question_score": 17, "tags": "plugins, plugin development, slug" }
Conditional Statements I have created Custom Post Type called - listing Also created custom taxonomy - listingcategories In listing categories, i have created two categories 1. music 2. features Now i want to create a conditional statement for music category I am trying this, but its not working <?php global $post; if (($post->post_type == 'listing') && is_category('music')) { //statement } ?> Am i using it right **is_category()** ? Please Help. Thanks Rajiv
<?php if( has_term( 'music', 'listingcategory' ) ) { //content1 } else { //content2 } ?> Got working using this <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy, conditional tags" }
Change permalink when page category selected in admin I'm using the Events Manager plugin which uses a custom post type of 'events' and a custom taxonomy of 'event-categories'. One of my events categories is 'Short courses'. When I check this category (in admin) I want the default of /events/page-title to change to /course/page-title, and revert when the category is unchecked. Does anyone know if this is possible?
I decided on a different approach. Keep the default permalinks in admin, then add a rewrite to allow /course: add_rewrite_rule('^course/([^/]*)/?', 'index.php?event=$matches[1]', 'top'); // single event Then I can update my theme templates with the course/ urls where needed.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, wp admin, hooks" }
Add a Custom Field in Comment Box AFTER text area BUT BEFORE Send button I was inspired by this Q&A: Add a Custom Field in Comment Box next to the Text area but I have to insert the custom field after the textarea but before the Send button. I did not found the proper action to customize and I guess it not exists at all. comment_form_after_fields puts my output before textarea comment_form_after puts my output after Send button Am I wrong? add_action( 'comment_form_after', 'test'); function test(){ echo "TEST"; } add_action( 'comment_form_after_fields', 'test'); function test(){ echo "TEST"; }
Filter `comment_form_defaults` and add your code to the textarea. Sample code, not tested: add_filter( 'comment_form_defaults', 'wpse_120049_extend_textarea' ); function wpse_120049_extend_textarea( $args ) { $args['comment_field'] .= '<p>Extra text.</p>'; return $args; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "actions, comment form" }
How to change to local video player on shortcode ultimate to video.js? I have Shortcodes Ultimate plugin, and I would like to change this plugin video player to Video.js player. That's becouse, the original player is very afful, and instabil, and you can't control volume, can't replay the video,so this player very insufficient. I can't use the original wordpress player,becouse the plugin use the same short code as the wordpress short code and this do a little conflict. Example for the plugin shortcode: [video url=" poster=" title="Castiel találkozása a szex-el"] I can't delete this plugin,becouse I use some usefull function in here. So the bestway be if I can change the video player to Video.js player.
You can try to re-register the default WordPress `[video]` shortcode: /** * Re-Register the default [video] shortcode * WPSE: 120057 */ function wpse_120057() { add_shortcode( 'video', 'wp_video_shortcode' ); } add_action( 'plugins_loaded', 'wpse_120057' ); Here is the file in the _Shortcodes Ultimate_ plugin that contains the `[video]` shortcode registration.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "shortcode, video player" }
How do I turn a post thumbnail into a background image? I believe the answer o this question was posted on this page, but it is still not clear to me. The snippets are scattered all over the discussion and several glitches happen when I implement them.
I was looking for a code snippet that will extract the URL of a post thumbnail to be used as a background image. Through research elsewhere, the best answer I found is the code snippet below: <div style="background: url(<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'large', true); echo $image_url[0]; ?>)"></div> This code sets the large thumbnail of a post as the background image in this div tag. From here I believe you should be able to modify this code to your particular situation.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, post thumbnails, thumbnails" }