New answers tagged

4

You might be a little confused as to the purpose and function of nonces in WordPress. Recommended reading: WordPress Nonces An Introduction to WordPress Nonces with Examples Protect_Queries_Against_SQL_Injection_Attacks A nonce is a "number used once" to help protect URLs and forms from certain types of misuse, malicious or otherwise. Nonces help ...


0

Had similar problem ($post was null inside the rendering function). Sorted with the solution below: function bg_post_categories_shortcode( $atts, $content = null ) { global $post; $categories = get_the_category_list( ', ', '', $post->ID); return '<div class="gi__categories">' . $categories . '</div>'; } ...


1

First open your wp-config.php which is located in the root WordPress directory. Then add the following line inside the main php tag: define('WP_MEMORY_LIMIT', '64M'); We just increased the memory limit to 64M. If you still get the error after this fix, then please contact your host. Most likely, they would have to go in their php.ini file to increase the ...


2

To start with, you need to fix the define of CSV_PATH: define('CSV_PATH',dirname(__FILE__)); as without that, $handle will be false - no file opened or data read. ...then before you run it take another look becaue $col4 and $col5 are not set anywhere either...


1

Create a new theme folder next to your current theme and name it, ThemeName Child Theme In the new child theme folder create a file names style.css In the header of that file add this, /* Theme Name: My Child Theme Theme URI: http://www.example.com/myTheme Description: your Child Theme Author: your name Author URI: ...


0

The default themes, TwentyXXXX, do it somewhat like this: add_action( 'wp_enqueue_scripts', 'wpse217390_enqueue_google_fonts' ); function wpse217390_enqueue_google_fonts() { $query_args = array( 'family' => 'Dosis:400,600,700|Roboto:400,400italic,700,700italic' ); wp_register_style( 'google-fonts', add_query_arg( $query_args, ...


0

This can be done like this: function redirect_user ($user_login, $user) { wp_redirect( "/profile/" .$user_login );// $user_login is $user->user_login exit; } add_action('wp_login', 'redirect_user', 10, 2);


0

This little plugin shows the user role 'author' only its own categories & posts. So you can edit it for your own post-type and taxonomy. /* Plugin Name: Show own categories Description: This plugin shows the user role 'author' only its own categories & posts Version: 0.1 Author: Soren Wrede License: GPL2 License URI: ...


0

Try placing a header() function instead of wp_redirect, so header("Location: mysite.com/profile/username");


0

I recommend you to store it in WordPress options table using function add_option() function as this is site specific data and not post/category specific.


1

WordPress theme files are called thru functions/classes, so variables declared in functions.php are not recognized by other theme files, until you specify you want to use the global value of the variable. Do so like this in your theme template files: global $mysite_address_url; you can then use $mysite_address_url as you'd like. To read more about PHP's ...


0

You can either place entire code into an array as below: $safe= array( 'get_template_part(\'content/block\', \'branding\');', 'get_template_part(\'content/block\', \'footer\');' ); And then introduce the below check into your function to make sure that no kind of code other than what you already listed can be sent to eval: function ...


0

Use get_categories first to get all the post categories to use in the form, then loop through them to display a multicheck input... function hierarchical_category_inputs ($cat, $indent) { $cats = get_categories('hide_empty=false&orderby=name&order=ASC&parent='.$cat); $indent++; if ($cats) { foreach ($cats as $cat) { ...


2

You can do this several ways, it just depends on how specific you want to get. Like do you need to disable for only one user with the ID of 21 or was that just an example? And are you trying to disable several pages or just a couple? For example you can do this to redirect the dashboard to the edit posts page if not an administrator. ...


0

After quite a bit of trial and error, I got the code set up correctly for the WordPress loop. I put it into a shortcode. Here it is: add_shortcode( 'partnerlogos', 'display_partner_logos' ); function display_partner_logos(){ // Define the query $args = array( 'post_type' => 'dnf_partner_logos', 'post_status' => 'publish' ); ...


1

This question has been answered on Stack Overflow before: http://stackoverflow.com/a/14626254/844732 add_action( 'admin_head', 'check_page_template' ); function check_page_template() { global $post; if ( 'page-homepage.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) { // The current page has the foobar template assigned ...


0

Is this happening if you remove the pre_get_posts hook? Either way, you can try wrapping the code in a conditional. while (have_posts() ) : the_post(); if ( 0 < intval( the_ID() ) { ... } endwhile; This is not quite as good as limiting the number of records returned by the query but it doesn't hurt to validate as you go along anyways.


1

Use this: $query = new WP_Query( array( 'cat' => 4 ) ); Where 4 is the ID of the top-level category (Blackburn). This query will in clude subcats. Reference - WP_Query


0

You have to load your javascript Snippet inside your header. You'll have to options: Edit your themes header.php and put the code before the closing tag Insert your code into the header with a custom function inside your functions.php function my_custom_js() { echo '<script type="text/javascript"> jQuery(document).ready(function($){ ...


2

You can enqueue all your scripts the same way as you enqueue jQuery. Register and enqueue all your Javascripts like this (in your load_jquery function) wp_register_script ( 'yourscripthandle', //string $handle: a string to identify this script get_bloginfo( 'template_url' ) . '/js/yourcustomjs.js', //string $src: Path of your script file array ...


-2

We have a company that allows banks to register within their site with a membership.... If you're dealing with banking info (and not even financial data), employee data, course registration, tickets, etc., you're absolutely foolish to pull a random php function from the web and try to integrate it into a WordPress theme and expect the results to work ...


0

Can't you just hardcode the keys for the different crops and then use Regenerate Thumbnails ?


0

Use the checked function. https://codex.wordpress.org/Function_Reference/checked The HTML you want to render should look like this: <input ... value="hide" checked="checked" />Hide from these locations.</br> <input ... value="show" />Only show to these locations.</br> What you're getting instead is probably somthing like this: ...


0

1. Simply call the template part in each place. <?php get_template_part('content','left'); ?> and <?php get_template_part('content','right'); ?> You would then create content-left.php and content-right.php templates. 2. A different approach would be to call do_action there instead. eg. <?php do_action('template_content_left'); ?> ...


-1

What about $coupon->customer_email; ?


1

I have solved my problem by adding $myCode -> change_url(); and add_action('wp_head', array($myCode, 'print_header_scripts')); <?php class some_code { function change_url() { $domain_name = $_SERVER['SERVER_NAME']; $country_code = get_country_code(); if ($country_code == "PK") { header("location: ...


1

Here you go: According to documentation of get_post_meta , It will return a single value if the third parameter is true. It should be false to return an array. <?php $price = get_post_meta(get_the_ID(),'si-price'); foreach ($price as $element) { if (is_numeric($element)) { echo '$' . $element; } else { ...


1

Looks like you are just missing a "." to concatenate the string and variable. It should read: echo '$' . $price;


2

human_time_difference() will not work here as it returns a string in a human readable form. However, we can use some of the logic used there to construct a workable function You can try the following: (Untested) function get_custom__time_diff() { global $post; // Get the current time $current_time = time(); // Get the post date ...


1

wp_logout is being triggered server side when the user is logging out, but the fact that it is being triggered do not indicate that there is a browser on the other side that actually triggered it. For example a user might log out via Ajax and then the JS code will not be evaluated. In any case, it is much better to define a logged out user as one that do ...


1

Well, you wouldn't need a walker for that, if it's simply adding a data attribute or something like that you could just use the items_wrap parameter. View wp_nav_menu() in Resources: $items_wrap = '<div class="top-nav" mine="something">'; $items_wrap .= '<ul id="%1$s" mine="something2" class="nav %2$s">%3$s</ul>'; $items_wrap .= ...


0

So I have done figured out a solution using php Ill explain below: So I created a var and called it white. It has a empty string that I used and an if statement then I used the WordPress function is_front_page <?php $white = ""; if( !is_front_page() ) { $white = 'scrolled'; } ?> Then in my Navbar class I added this: <?php ...


0

Most WordPress themes take advantage of a function called body_class() which outputs specific classes to the body tag. Implementation looks something like this: <body <?php body_class(); ?>> This will put a unique class on the homepage of your website that won't be on any of the other pages so you could target that specifically in jQuery or ...


0

To check if woocommerce or anyother plguin is active, paste the following code on the template where you want to display the message. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { echo 'WooCommerce is active.'; } else { echo 'WooCommerce is not Active.'; }


1

It is all fine. You just need to declare variable global first then you can set the value of this and access globally. function my_free_shipping( $is_available ) { global $woocommerce, $product_notfree_ship; // set the product ids that are $product_notfree_ship $product_notfree_ship = array( '1', '2', '3', '4', '5' ); Then again declare it globally when ...


0

Declare it as global $product_notfree_ship as you are doing, just access it via this $GLOBALS['product_notfree_ship'];


0

I actually just wanted to make a comment but..(reputation is too low) so doing it this way. If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict( true ) from the second version will return the globally scoped jQuery variables to those of the first version. So to solve your 'issue' (if I am correct) the ...


0

You need to close the PHP tag before you write html code for image source and then reopen the PHP tag once your HTML is finished. <?php function thumbImg() { if ( has_post_thumbnail() ) { the_post_thumbnail( array(54,54) ); } else { ?> <img src='<?php echo $data['featured_img']; ?>' alt='<?php the_title(); ...


1

ohwild_entry_meta_header() is missing the closing }.


-1

Have you tried using FTP to replace header.php on your server with the original from your theme files?


1

In case anyone else needs the code, this is how I solved it. @pieter-goosen was right, I did need to query the correct posts, but the real trick was matching the date format from the jquery datepicker when running the post query. Check the date formats below, jquery is 'yy-mm-dd', and the php equivalent is 'Y-m-d'. So the js for the datepicker was: ...


1

You need to recurse into the shortcode content ($m[5] as returned by get_shortcode_regex()), the standard way being to use preg_replace_callback(): public function wrapShortcode( $content ) { $content = preg_replace_callback( '/' . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $content ); remove_filter( ...


2

This looks like a hack, probably in W3TC. Try disabling all the Plugins one by one, and if it doesn't go away, try switching to the default theme. If that did not work, install WordPress from scratch, and transfer the database to it. If you prefer another debug mode, I suppose your script gets hooked into WordPress in the wp_footer action. To verify that, ...


0

[%%LINKS%%]is very suspicious. It's inside a display:none div, so any links output by a function will be in page source for SEO purposes, but won't display on the site. You probably did get hacked. Try using Adminer « WordPress Plugins to search the database for that string. If you find it, carefully follow ...


0

$arr['Zumpito_event_full_day'] = isset( $_POST['Zumpito_event_full_day'] ) ? esc_attr( $_POST['Zumpito_event_full_day]) : ''; this should solve your first notice explanation is this in the link given by you


1

You are mixing html and php content. You should write it like this: <?php function thumbImg() { if ( has_post_thumbnail() ) { the_post_thumbnail( array(54,54) ); } else { echo "<img src='{$data['featured_img']}' alt='".get_the_title()."' />"; } } ?> This way, you don't need to open and close again the php tag.


1

There are few issue with your code When using WP_Query in conjuction with the_post() or using get_posts() in conjuction with setup_postdata( $post ), you need to reset the $post global with wp_reset_postdata(), not wp_reset_query(). wp_reset_query() is used in conjuction with query_posts() which you should never ever use You would want to reset posdata ...


0

This change is untested: if( $file === '' || ! isset( $file ) || ! file_exists( $file ) ) {


1

These are CSS classes for styling... comment-author-admin bypostauthor For (your) example: .commentlist .byuser {background-color: black;} .commentlist li ul.children li.byuser {border-top: 10px solid #e18728;}


1

preg_replace to the one-call rescue. /\w+/ will match words, while the third argument of preg_replace() will specify the number of matches. Since you want to remove them then we just pass an empty string as the replacement. $str = 'These are some words. But the first two will not remain.'; // pattern, replacement, string, limit echo preg_replace( '/\w+/', ...



Top 50 recent answers are included