Category: Wordpress

Learn about WordPress

  • WordPress get_option(): Syntax, Defaults, Autoload & Pitfalls

    WordPress get_option(): Syntax, Defaults, Autoload & Pitfalls

    Updated 16 October 2026 · By Abhilash Sahoo, Infyways

    Quick answer: get_option() reads a single site-wide setting from the WordPress wp_options table.

    $value = get_option( 'option_name', $default );
    • Returns the stored value (WordPress unserializes arrays and objects for you).
    • Returns false if the option doesn’t exist and you passed no default; otherwise it returns your $default.
    • Values usually come back as strings — even numbers (get_option('page_for_posts') → "0").
    • Autoloaded options are loaded once per request, so repeated calls don’t hit the database again.

    Every result on this page was produced on a real WordPress 7.1.3 install (PHP 8.4) with WP-CLI — not copied from the manual.

    What are the parameters and return value?

    Real wp-cli output showing get_option return values and default parameter

    The function signature from the official developer reference is:

    get_option( string $option, mixed $default_value = false )
    Parameter Type Notes
    $option string The option name (the option_name column). Required.
    $default_value mixed Returned when the option does not exist. Defaults to false.

    Here is the real output for core settings, a missing option, and a missing option with a default:

    get_option("blogname")          "WP Test"
    get_option("admin_email")       "a@example.com"
    get_option("page_for_posts")    "0"        // a string, not an int
    get_option("does_not_exist")              false
    get_option("does_not_exist","fallback")   "fallback"

    How do I use get_option? (examples)

    Read a core setting

    $title = get_option( 'blogname' );
    $email = get_option( 'admin_email' );
    $per_page = (int) get_option( 'posts_per_page' ); // cast, because it's a string

    Read your plugin’s settings array

    get_option returning an array and the serialized value stored in wp_options

    Store one array per plugin instead of dozens of separate options. WordPress serializes it on write and unserializes it on read automatically:

    update_option( 'iw_settings', array( 'layout' => 'grid', 'cols' => 3 ) );
    $opts = get_option( 'iw_settings', array() );   // always returns an array
    echo $opts['layout'];                            // "grid"

    In the database that single row holds a:2:{s:6:"layout";s:4:"grid";s:4:"cols";i:3;} — but you never call serialize() or unserialize() yourself.

    Save, update and delete options

    Real output of add_option, update_option and delete_option return values

    get_option() has three partners. Watch their return values:

    Function Does Returns
    add_option() Creates an option (fails quietly if it exists) true / false
    update_option() Creates or updates; the one you’ll use most true if changed, false if unchanged or failed
    delete_option() Removes the option true / false

    Real run:

    update_option("iw_demo","world")   // true  (value changed)
    update_option("iw_demo","world")   // false (same value — NOT an error)
    delete_option("iw_demo")           // true
    get_option("iw_demo","GONE")       // "GONE"

    The second update_option() returning false trips people up constantly: it means “nothing changed”, not “it failed”. Don’t treat it as an error.

    How does autoload work (and what changed in WordPress 6.6)?

    WordPress 6.6+ autoload values auto, on and off verified on WordPress 7.1.3

    Every option row has an autoload flag. Autoloaded options are pulled into memory in one query at the start of each request by wp_load_alloptions(), so reading them later is free. WordPress 6.6 changed the values stored in that column. Confirmed on WordPress 7.1.3:

    How you add it Stored value (6.6+) Behaviour
    add_option(,) (let core decide) 'auto' Core auto-decides based on size
    Legacy 'yes' 'on' Always autoloaded
    Legacy 'no' 'off' Loaded on demand

    Before 6.6 the column only held 'yes'/'no'. If you query the autoload column directly, your code must now also handle 'auto', 'on' and 'off'. Passing 'yes'/'no' still works for backward compatibility. Keep large or rarely used options off autoload so they don’t bloat every page load — our WordPress plugin development work almost always starts with trimming an overgrown autoloaded options set.

    Does get_option hit the database every time?

    Autoloaded options add zero DB queries; pre_option and option filters demo

    No. For an autoloaded option, we read it five times in a row and measured the queries:

    5 × get_option("iw_auto")  →  0 extra DB queries

    All autoloaded options are already in memory. A non-autoloaded option is fetched on first use and then cached (via the object cache if one is configured). So get_option() is cheap; the thing to manage is what you autoload, not how often you call it.

    How do I filter or override a value?

    Two filters wrap every read:

    • option_{$option} — change the value after it’s read from the database.
    • pre_option_{$option} — return any non-false value to short-circuit the read entirely (the database is never touched).
    add_filter( 'option_iw_color', fn($v) => strtoupper($v) );   // "blue" → "BLUE"
    add_filter( 'pre_option_iw_color', fn() => 'SHORTCIRCUIT' );  // DB skipped
    

    Both verified live. pre_option_ is how plugins force a setting (for example, defining it as a constant in wp-config.php).

    get_option vs post meta, theme mods and transients

    get_option vs get_post_meta, get_theme_mod, get_transient and get_site_option

    Pick the right storage API for the job:

    Function Use it for Scope Expires?
    get_option() Site-wide settings Whole site No
    get_post_meta() Data attached to one post — see our update_post_meta guide A single post No
    get_theme_mod() Theme / Customizer settings Active theme (stored as one option) No
    get_transient() Temporary cached data (API responses, expensive queries) Whole site Yes
    get_site_option() Network-wide settings on multisite Whole network No

    Multisite note: on a network, get_option() reads the current site’s settings, while get_site_option() reads network-wide settings. A transient is just an option with an expiry — use it when the data can be regenerated, and get_option() when it must persist.

    Reading options over the REST API

    Settings that are registered with register_setting() and marked show_in_rest are exposed at /wp-json/wp/v2/settings (authenticated). We queried it on the test site and it returned the whitelisted options:

    GET /wp/v2/settings → 200
    title, description, timezone, posts_per_page, show_on_front, page_for_posts, ...
    title = "WP Test"   posts_per_page = 10

    Only options that are explicitly registered for REST appear here — your custom options won’t show up unless you register them. This is the modern, safe way for a block editor or headless front end to read and write settings without touching the database directly.

    Common mistakes with get_option()

    Mistake What happens Fix
    Expecting an integer or boolean You get a string ("0", "1") Cast: (int), or compare loosely with care
    Treating false as “error” A missing option and a stored false both return false Pass a unique default and compare, or use get_option() === false
    Reading update_option() false as failure You throw an error when nothing was wrong Remember false = “value unchanged”
    Autoloading huge options Every page load gets slower Add big/rarely used options with autoload off
    Running get_option() too early Returns the default before options load Read inside a hook (e.g. init), not at file top level
    Not escaping before output Stored HTML can break or XSS your page echo esc_html( get_option('blogname') );

    Frequently asked questions

    What does get_option() do in WordPress?

    It reads one named setting from the wp_options table and returns its value, automatically unserializing arrays and objects. It’s the standard way to read site-wide configuration saved by WordPress core, themes and plugins.

    What is the default return value of get_option()?

    false. If the option doesn’t exist and you didn’t pass a second argument, you get false; if you passed a default, you get that default instead.

    Why does get_option() return false?

    Either the option name doesn’t exist, or the stored value genuinely is false. Because the two look identical, pass a unique default (get_option('key','__missing__')) and compare, so you can tell “not set” from a real false.

    Does get_option() return a string or the original type?

    Scalars (numbers, booleans you stored as text) usually come back as strings, so cast them. Arrays and objects are returned in their original type because WordPress unserializes them for you.

    Is get_option() cached?

    Yes. Autoloaded options are loaded once per request into memory, so repeated calls add no database queries. Non-autoloaded options are fetched on first use and cached after that (in the object cache if one is active).

    How do I get an array from get_option()?

    Store the array with update_option() and read it back with get_option('key', array()). WordPress handles serialization both ways, so you get a native PHP array. Passing array() as the default avoids errors when the option is missing.

    What changed about autoload in WordPress 6.6?

    The autoload column now stores 'auto', 'on' and 'off' instead of only 'yes'/'no'. Passing 'yes'/'no' still works, but code that inspects the raw column value must handle the new strings. Core also auto-decides autoload based on option size.

    What’s the difference between get_option() and get_site_option()?

    On a single site they’re effectively the same. On multisite, get_option() reads the current site’s settings and get_site_option() reads network-wide settings shared across all sites.

    Should I use the Options API or the Settings API?

    The Options API (get_option/update_option) is the low-level storage. The Settings API builds admin forms on top of it with validation and sections. Use the Settings API to register and render settings pages; it still stores everything as options you read with get_option().

    How do I read an option over the REST API?

    Register it with register_setting() using show_in_rest, then read it from /wp-json/wp/v2/settings with an authenticated request. Unregistered options are not exposed.

    Working in WordPress regularly? You might also like our guides on update_post_meta(), getting the featured image URL, and getting the current page name.

  • How to Get the Featured Image URL in WordPress (Code Examples)

    How to Get the Featured Image URL in WordPress (Code Examples)

    Updated 15 October 2026 · By Abhilash Sahoo, Founder, Infyways

    To get the featured image URL in WordPress, use get_the_post_thumbnail_url(). For the current post, at full size:

    <?php echo esc_url( get_the_post_thumbnail_url( get_the_ID(), 'full' ) ); ?>

    It returns the image URL as a string, or false when the post has no featured image. Pass a post ID to get the image for any post, and a size name such as 'thumbnail', 'medium', 'large' or 'full' to choose the size.

    In short: get_the_post_thumbnail_url( $post, $size ) for the URL, get_post_thumbnail_id() for the attachment ID, wp_get_attachment_image_src() when you also need width and height, and _embed=wp:featuredmedia in the REST API.

    How do I get the featured image URL inside the loop?

    PHP code in single.php using has_post_thumbnail() and get_the_post_thumbnail_url() in the loop, plus a by-ID example with a fallback image
    Using get_the_post_thumbnail_url() in the loop and by post ID, with a fallback.

    Call get_the_post_thumbnail_url() without a post argument. It uses the global $post, so it works in single.php, index.php, archive templates and any WP_Query loop. Check has_post_thumbnail() first so you don’t print an empty src:

    <?php if ( has_post_thumbnail() ) : ?>
        <img src="<?php echo esc_url( get_the_post_thumbnail_url( null, 'large' ) ); ?>"
             alt="<?php echo esc_attr( get_the_title() ); ?>">
    <?php endif; ?>

    The signature is get_the_post_thumbnail_url( int|WP_Post|null $post = null, string|int[] $size = 'post-thumbnail' ): string|false. It was introduced in WordPress 4.4.

    How do I get the featured image URL by post ID?

    Diagram of how WordPress resolves a featured image URL: post, thumbnail ID from _thumbnail_id meta, attachment, then URL in thumbnail, medium, medium_large, large or full size
    From post to thumbnail ID to attachment to a URL in the size you ask for.

    Pass the post ID (or a WP_Post object) as the first argument. This works anywhere, including outside the loop, in shortcodes, widgets and REST callbacks:

    $post_id = 123;
    $url     = get_the_post_thumbnail_url( $post_id, 'full' );
    
    if ( $url ) {
        echo esc_url( $url );
    }

    If you need the attachment ID instead, use get_post_thumbnail_id( $post_id ). It returns the attachment ID, or false if there is none.

    How do I get a specific image size?

    The $size argument accepts any registered size name or an array of width and height in pixels:

    get_the_post_thumbnail_url( $post_id, 'thumbnail' );    // Settings > Media size
    get_the_post_thumbnail_url( $post_id, 'medium_large' ); // 768px wide by default
    get_the_post_thumbnail_url( $post_id, 'full' );         // original upload
    get_the_post_thumbnail_url( $post_id, array( 600, 400 ) );

    The default is 'post-thumbnail', a special size registered when a theme adds post-thumbnail support. It is not the same as the 'thumbnail' size in Settings > Media.

    When you also need the width and height, use wp_get_attachment_image_src(). It returns an array: index 0 is the URL, 1 the width, 2 the height, and 3 whether the image is a resized version:

    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' );
    
    if ( $image ) {
        list( $url, $width, $height ) = $image;
    }

    How do I get the featured image URL from the REST API?

    Example WordPress REST API response with _embed=wp:featuredmedia showing featured_media, source_url and media_details sizes
    A trimmed REST API response: read source_url from _embedded wp:featuredmedia.

    Posts in the REST API only include featured_media, the attachment ID. Add _embed=wp:featuredmedia to get the media object in the same request, then read source_url:

    GET /wp-json/wp/v2/posts/123?_embed=wp:featuredmedia
    fetch( '/wp-json/wp/v2/posts/123?_embed=wp:featuredmedia' )
      .then( ( res ) => res.json() )
      .then( ( post ) => {
        const media = post._embedded?.['wp:featuredmedia']?.[0];
        const url   = media?.source_url;                              // full size
        const thumb = media?.media_details?.sizes?.thumbnail?.source_url;
      } );

    If you use _fields to slim the response, include _links and _embedded, or the embed is dropped: ?_embed=wp:featuredmedia&_fields=id,featured_media,_links,_embedded. We tested this on our own site. Without _embed, request /wp-json/wp/v2/media/{featured_media} as a second call.

    How do I show the featured image in a block theme?

    Block themes don’t use PHP templates for this. Use the Post Featured Image block (core/post-featured-image) inside a single template or a Query Loop. Its settings include the image size (sizeSlug), aspect ratio, whether it links to the post (isLink), and an option to use the first image in the post when no featured image is set (useFirstImageFromPost).

    You only need PHP in a block theme when you build a custom block or a render callback. There, get_the_post_thumbnail_url() works the same way.

    How do I set a fallback image when there is no featured image?

    Because the function returns false when there is no featured image, fall back with a short check:

    $url = get_the_post_thumbnail_url( get_the_ID(), 'large' );
    
    if ( ! $url ) {
        $url = get_theme_file_uri( 'assets/images/default-featured.jpg' );
    }

    In a block theme, the Post Featured Image block’s “use first image from post” option is a no-code alternative.

    How do I get the featured image alt text and srcset?

    PHP code getting the featured image alt text with _wp_attachment_image_alt, srcset with wp_get_attachment_image_srcset and width and height with wp_get_attachment_image_src
    Getting the alt text, srcset and dimensions from the thumbnail ID.

    The URL functions return only the URL. The alt text is stored as attachment meta, and srcset is built from the registered sizes:

    $thumb_id = get_post_thumbnail_id( $post_id );
    $alt      = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
    $srcset   = wp_get_attachment_image_srcset( $thumb_id, 'large' );
    $url      = wp_get_attachment_image_url( $thumb_id, 'large' );

    If you just want a complete, responsive <img> tag with alt, srcset and sizes, use get_the_post_thumbnail() or the_post_thumbnail() instead of building it yourself.

    Which featured image function should I use?

    Comparison table of get_the_post_thumbnail_url, wp_get_attachment_image_url, wp_get_attachment_image_src, the_post_thumbnail and get_post_thumbnail_id: what each takes and returns
    Which featured image function to use.
    Function Takes Returns Use it when
    get_the_post_thumbnail_url( $post, $size ) Post ID or object (optional) URL string or false You need the featured image URL
    wp_get_attachment_image_url( $attachment_id, $size, $icon ) Attachment ID URL string or false You already have an attachment ID
    wp_get_attachment_image_src( $attachment_id, $size, $icon ) Attachment ID Array (URL, width, height, resized) or false You also need width and height
    the_post_thumbnail( $size, $attr ) Current post in the loop Prints an <img> tag You want the full responsive image tag output
    get_post_thumbnail_id( $post ) Post ID or object (optional) Attachment ID or false You need the ID for alt text, srcset or other sizes

    Signatures checked against the WordPress Code Reference on 15 October 2026.

    Why is get_the_post_thumbnail_url() not working?

    • The theme has no featured image support. Add it in functions.php: add_action( 'after_setup_theme', function () { add_theme_support( 'post-thumbnails' ); } );. Block themes and most modern themes already have it.
    • It returns false. The post has no featured image set, or you are outside the loop without passing a post ID. Use has_post_thumbnail( $post_id ) to check.
    • It returns the wrong size. The size name may not be registered, or the image was uploaded before the size existed. Regenerate thumbnails (for example with WP-CLI: wp media regenerate) so the missing sizes are created.
    • The URL is the full image instead of the size you asked for. WordPress falls back to a larger file when the requested size does not exist for that image. Regenerate thumbnails or pick a registered size.
    • Nothing prints. get_the_post_thumbnail_url() returns a value; it does not echo. Use echo esc_url( ... ).
    • The REST response has no _embedded. Add _embed=wp:featuredmedia, and include _links,_embedded if you use _fields.

    Frequently asked questions

    How do I get the featured image URL in WordPress?

    Use get_the_post_thumbnail_url(). Inside the loop call it without arguments; elsewhere pass the post ID, for example get_the_post_thumbnail_url( 123, 'full' ).

    What does get_the_post_thumbnail_url() return if there is no featured image?

    It returns false, so check the result or call has_post_thumbnail() before printing it.

    How do I get the full-size featured image URL?

    Pass 'full' as the size: get_the_post_thumbnail_url( $post_id, 'full' ). Without a size it returns the 'post-thumbnail' size.

    How do I get the featured image ID?

    Use get_post_thumbnail_id( $post_id ). It returns the attachment ID, or false if the post has no featured image.

    How do I get the featured image URL in the REST API?

    Request the post with ?_embed=wp:featuredmedia and read _embedded['wp:featuredmedia'][0].source_url, or fetch /wp-json/wp/v2/media/{featured_media} separately.

    How do I get the featured image width and height?

    Use wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' ). It returns the URL, width, height and whether the image is resized.

    How do I get the featured image alt text?

    Read the attachment meta: get_post_meta( get_post_thumbnail_id( $post_id ), '_wp_attachment_image_alt', true ).

    Why does my theme not show the Featured Image box?

    The theme hasn’t declared support. Add add_theme_support( 'post-thumbnails' ) on the after_setup_theme hook in functions.php.

  • update_post_meta() in WordPress: Return Values, prev_value, Arrays & REST

    update_post_meta() in WordPress: Return Values, prev_value, Arrays & REST

    Updated 16 October 2026 · By Abhilash Sahoo, Infyways

    Quick answer: update_post_meta() saves a custom field (post meta) value. If the key doesn’t exist for that post, it adds it; if it does, it updates it.

    $result = update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' );
    • Returns the new meta ID (int) when it adds a row, true when it changes a value, and false on failure or when the value is unchanged.
    • Without $prev_value it overwrites every row with that key.
    • Arrays are serialized for you, and backslashes are stripped unless you wrap the value in wp_slash().

    Every result on this page comes from a real WordPress 7.1.3 install (PHP 8.4) tested with WP-CLI, not copied from the manual.

    What are the parameters of update_post_meta()?

    The signature from the official WordPress developer reference is:

    update_post_meta( int $post_id, string $meta_key, mixed $meta_value, mixed $prev_value = '' ): int|bool
    Parameter Type Notes
    $post_id int Required. If you pass a revision ID, WordPress saves the meta on the parent post instead.
    $meta_key string Required. Start it with _ to hide it from the Custom Fields box.
    $meta_value mixed Required. Arrays and objects are serialized. Expected to be slashed.
    $prev_value mixed Optional. Only update rows that currently hold this value. Default '' means all rows with the key.

    Internally, update_post_meta() is a thin wrapper: it swaps a revision ID for its parent and then calls update_metadata( 'post', ... ), the same engine behind user, term and comment meta.

    What does update_post_meta() return?

    Real wp-cli output of update_post_meta return values: meta ID, true and false
    Situation (tested) Return
    Key didn’t exist, so a row was added Meta ID, e.g. 5
    Key existed and the value changed true
    Same value as stored false
    Integer 5 stored, then string "5" saved false (treated as unchanged)
    $post_id of 0, or an empty $meta_key false
    A post ID that doesn’t exist (999999) Meta ID: the row is still added
    A filter on update_post_metadata short-circuits it Whatever the filter returns

    Two practical lessons follow. First, don’t treat false as an error: it usually means “nothing to change”. Second, WordPress doesn’t check that the post exists, so validate the ID yourself or you’ll leave orphaned rows in wp_postmeta:

    if ( ! get_post( $post_id ) ) {
        return; // avoid orphaned meta
    }
    $result = update_post_meta( $post_id, 'color', 'blue' );
    if ( false === $result && get_post_meta( $post_id, 'color', true ) !== 'blue' ) {
        error_log( 'Saving color failed' ); // a real failure
    }

    How do I use update_post_meta()? (examples)

    Save a custom field on save_post (secure version)

    add_action( 'save_post_product', function ( $post_id ) {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
        if ( wp_is_post_revision( $post_id ) ) return;
        if ( ! isset( $_POST['iw_price_nonce'] ) || ! wp_verify_nonce( $_POST['iw_price_nonce'], 'iw_save_price' ) ) return;
        if ( ! current_user_can( 'edit_post', $post_id ) ) return;
    
        if ( isset( $_POST['iw_price'] ) ) {
            $price = sanitize_text_field( wp_unslash( $_POST['iw_price'] ) );
            update_post_meta( $post_id, '_iw_price', $price );
        }
    } );

    $_POST data is already slashed by WordPress, so wp_unslash() it before sanitizing. update_post_meta() then strips slashes again, so plain text values come out right. See the slashing section below for the case where this goes wrong.

    Read the value back

    $price = get_post_meta( $post_id, '_iw_price', true ); // single value (string)

    Change a page template

    update_post_meta( $page_id, '_wp_page_template', 'templates/full-width.php' );

    Increment a counter

    $views = (int) get_post_meta( $post_id, 'iw_views', true );
    update_post_meta( $post_id, 'iw_views', $views + 1 );

    Under heavy traffic, two requests can read the same number and both write +1. For accurate counters, use a custom table or an atomic SQL UPDATE.

    How does the $prev_value parameter work?

    Real output showing add_post_meta multiple values and the update_post_meta prev_value parameter

    A post can hold several rows with the same key (added with add_post_meta()). $prev_value picks which one to change:

    Call (rows: happy, sad) Return Rows afterwards
    update_post_meta( $p, 'mood', 'excited', 'sad' ) true happy, excited
    update_post_meta( $p, 'mood', 'calm', 'nope' ) false unchanged (no match)
    update_post_meta( $p, 'mood', 'calm' ) true calm, calm (every row overwritten)

    That last row is the classic bug: calling update_post_meta() without $prev_value on a multi-value key silently destroys the other values.

    Unique vs multiple values: add_post_meta() and get_post_meta()

    Call Real result
    add_post_meta( $p, 'mood', 'happy' ) 8 (meta ID)
    add_post_meta( $p, 'mood', 'sad' ) 9, so a second row is added
    add_post_meta( $p, 'mood', 'x', true ) false, because $unique is true and the key exists
    get_post_meta( $p, 'mood', true ) 'happy' (first row only)
    get_post_meta( $p, 'mood', false ) ['happy', 'sad']
    get_post_meta( $p, 'missing', true ) '' (empty string)
    get_post_meta( $p, 'missing', false ) [] (empty array)

    Because a missing key returns '', you can’t tell “empty” from “not set” with get_post_meta() alone. Use metadata_exists( 'post', $post_id, $key ).

    What happens when you save an array?

    update_post_meta storing an array as a serialized string and scalars returned as strings

    WordPress serializes arrays and objects on save and unserializes them on read. The real stored value for [12, 15, 18] is a:3:{i:0;i:12;i:1;i:15;i:2;i:18;}.

    • get_post_meta( $p, 'gallery', true ) returns the array. With false you get it nested one level deeper ([[12, 15, 18]]), which is a common source of “my array has an extra level” bugs.
    • Saving the identical array again returns false. Saving ['12','15','18'] (strings) returns true, because the serialized form differs.
    • Scalars come back as strings: 5 → '5', true → '1', false → '' (and the row still exists).
    • You can’t query inside serialized data with meta_query reliably. If you need to filter by a value, store it in its own key.

    Why do backslashes disappear? (wp_slash and JSON)

    update_post_meta stripping backslashes from JSON and the wp_slash fix

    For historical reasons, update_post_meta() expects the key and value to be slashed, and runs stripslashes() on them before saving. Our test results:

    You save You get back
    {"key":"value with \"quotes\""} {"key":"value with "quotes""}, which json_decode() can’t parse
    wp_slash( $json ) {"key":"value with \"quotes\""}, which decodes fine
    'C:\Users\demo' 'C:Usersdemo'
    ['p' => 'C:\Users'] ['p' => 'C:Users'] (arrays are stripped too)

    The rule is simple: if a value can contain a backslash (JSON, Windows paths, regex), wrap it in wp_slash(). Values from $_POST are the exception, since they arrive slashed. wp_unslash() them for sanitizing, and pass the result straight to update_post_meta() only if it contains no backslashes you need to keep.

    What are protected meta keys (underscore prefix)?

    Keys starting with _ are “protected”: is_protected_meta( '_price', 'post' ) returns true, and is_protected_meta( 'price', 'post' ) returns false. Protected keys are hidden from the classic Custom Fields meta box, so editors can’t change them by accident. That’s why WooCommerce uses _price and core uses _wp_page_template and _thumbnail_id (see our guide to getting the featured image URL in PHP). Protection is about the UI only. It isn’t security, as the REST test below shows.

    How do I delete post meta?

    Call (rows: a, b) Return Result
    delete_post_meta( $p, 'tag', 'a' ) true only “b” remains
    delete_post_meta( $p, 'tag' ) true all rows removed
    delete_post_meta( $p, 'tag' ) again false nothing to delete

    To remove a key from every post, use delete_post_meta_by_key( 'tag' ). Don’t set a value to '' when you mean “remove”, because that leaves a row behind.

    How do I update post meta through the REST API?

    Updating registered post meta through the WordPress REST API with register_post_meta

    Meta only appears in /wp-json/wp/v2/posts/<id> (and in the block editor) after you register it with show_in_rest:

    add_action( 'init', function () {
        register_post_meta( 'post', 'iw_price', array(
            'type'              => 'number',
            'single'            => true,
            'show_in_rest'      => true,
            'sanitize_callback' => fn( $value ) => round( (float) $value, 2 ),
            'auth_callback'     => fn() => current_user_can( 'edit_posts' ),
        ) );
        register_post_meta( 'post', 'iw_tags', array(
            'type'         => 'array',
            'single'       => true,
            'show_in_rest' => array( 'schema' => array( 'items' => array( 'type' => 'string' ) ) ),
        ) );
    } );

    Then send POST /wp-json/wp/v2/posts/4 with {"meta":{"iw_price":19.999,"iw_tags":["a","b"]}}. What we saw:

    Request Real response
    iw_price: 19.999, iw_tags: ["a","b"] Saved as 20 and ["a","b"] (the sanitize_callback ran)
    iw_price: "lots" rest_invalid_type: “meta.iw_price is not of type number.”
    An unregistered key (color) Silently ignored, with no error
    Anonymous GET on a published post Registered meta is visible, including _iw_secret
    'sanitize_callback' => 'floatval' Fatal error: “floatval() expects exactly 1 argument, 4 given”

    Three gotchas here that most tutorials miss:

    • auth_callback protects writes, not reads. Never register a secret with show_in_rest.
    • WordPress passes 4 arguments to sanitize_callback, and strict PHP built-ins like floatval crash. Wrap them in a closure.
    • The sanitize_callback also runs on direct PHP calls. Our update_post_meta( 4, 'iw_price', '7.456abc' ) was stored as '7.46'.

    Site-wide settings work the same way through register_setting(). See our WordPress get_option() guide for the REST settings endpoint.

    Is update_post_meta() slow? (meta cache and performance)

    Measured database queries for get_post_meta, update_post_meta and update_meta_cache

    WordPress loads all meta for a post in one query and keeps it in the object cache. We counted $wpdb->num_queries:

    Operation DB queries
    5× get_post_meta() on one post (cold cache) 1
    Other keys on the same post afterwards 0
    update_post_meta() with a changed value 3
    update_post_meta() with the same value 1
    get_post_meta() in a loop over 20 posts 20
    The same loop after update_meta_cache( 'post', $ids ) 1
    • When you loop over IDs you fetched yourself, prime the cache with update_meta_cache( 'post', $ids ). WP_Query does this for you by default (update_post_meta_cache).
    • Each changed update_post_meta() clears that post’s meta cache. In bulk imports, compare values first or batch your writes.
    • wp_postmeta has no index on meta_value, so meta_query filters on large sites get slow. Use a taxonomy or a custom table for data you filter on heavily.
    • On a case-insensitive collation (the default, utf8mb4_unicode_520_ci), update_post_meta( $p, 'color2', 'Y' ) updated our existing Color2 row, but get_post_meta( $p, 'color2', true ) returned ''. Keep keys lowercase.

    Which hooks fire when post meta is updated?

    Hook When
    update_post_metadata (filter) Before saving. Return anything other than null to short-circuit. In our test, returning false blocked the write.
    add_post_meta / added_post_meta Before and after a new row is inserted (on the first update_post_meta() call for a key)
    update_post_meta / updated_post_meta Before and after an existing row changes. Doesn’t fire when the value is unchanged.
    sanitize_post_meta_{$meta_key} Sanitizes the value (this is what register_post_meta‘s sanitize_callback hooks into)

    update_post_meta vs add_post_meta vs update_metadata

    Function Use it when
    update_post_meta() One value per key: add or overwrite
    add_post_meta() Several values per key, or “only add if missing” ($unique = true)
    delete_post_meta() Remove one value or the whole key
    update_metadata() The same logic for any object type ('post', 'user', 'term', 'comment')
    update_user_meta() / update_term_meta() The equivalents for users and terms
    wp_insert_post( [ 'meta_input' => [...] ] ) Setting meta while creating or updating a post in one call
    update_option() Site-wide settings, not per post (see get_option())

    What are the most common update_post_meta mistakes?

    1. Treating false as failure. An unchanged value also returns false.
    2. Overwriting multi-value keys. Leaving out $prev_value overwrites every row.
    3. Breaking JSON. Values with backslashes need wp_slash().
    4. Using get_post_meta( ..., false ) for an array. It’s nested one level deeper, so use true.
    5. Skipping nonce and capability checks on save_post, and not skipping autosaves.
    6. Saving meta for post IDs that don’t exist. WordPress adds the orphan row without complaint.
    7. Thinking _keys are private. They’re only hidden from the meta box, and REST can still expose them.
    8. Running get_post_meta() in a loop without priming the meta cache.
    9. Using built-in PHP functions as sanitize_callback, which causes an ArgumentCountError fatal.

    Need the current page’s slug or title before saving meta for it? See how to get the current page name in WordPress.

    FAQs

    What does update_post_meta return?

    The new meta ID (int) if the key didn’t exist, true if an existing value changed, and false on failure or when the new value equals the stored one.

    Why does update_post_meta return false?

    Most often because the value is identical to what’s stored (including 5 vs "5"). It also returns false for a post ID of 0, an empty key, a $prev_value that doesn’t match, or a filter that blocks the write.

    Does update_post_meta create the key if it doesn’t exist?

    Yes. It behaves like add_post_meta() and returns the new meta ID.

    Does update_post_meta check that the post exists?

    No. In our test, update_post_meta( 999999, 'x', 'y' ) returned a meta ID for a post that doesn’t exist. Check with get_post() first.

    How do I update only one of several values with the same key?

    Pass the current value as the fourth argument: update_post_meta( $id, 'mood', 'excited', 'sad' ).

    Can I store an array with update_post_meta?

    Yes. WordPress serializes it automatically. Read it back with get_post_meta( $id, $key, true ).

    Why are backslashes removed from my meta value?

    update_post_meta() runs stripslashes() on input. Wrap the value in wp_slash() to keep backslashes in JSON or file paths.

    What is the difference between update_post_meta and add_post_meta?

    update_post_meta() adds or overwrites. add_post_meta() always adds a new row, unless $unique is true and the key already exists.

    How do I update post meta via the REST API?

    Register the key with register_post_meta() and show_in_rest => true, then send {"meta":{"key":"value"}} to /wp-json/wp/v2/posts/<id> as an authenticated user. Unregistered keys are ignored.

    Does update_post_meta work on revisions?

    If you pass a revision ID, the meta is saved on the parent post. In our test, the revision itself got nothing.

    Is calling get_post_meta many times slow?

    Not for one post. All its meta loads in one query and is then cached. Across many posts, prime the cache with update_meta_cache(), or let WP_Query do it.

    Conclusion

    update_post_meta() is simple to call but easy to misuse. Treat false as “maybe unchanged”, use $prev_value for multi-value keys, wp_slash() anything with backslashes, register keys before using them over REST, and prime the meta cache in loops. If you’d rather have a team build custom fields, meta boxes or a full plugin for you, our WordPress plugin development service can help.

  • Literally the Best Platforms: Showit vs WordPress

    Literally the Best Platforms: Showit vs WordPress

    In the digital age, having a website is essential for businesses, bloggers, and creatives. Two platforms that stand out in the website design landscape are Showit and WordPress. But which one is right for you? This article will provide a detailed comparison to help you make the best choice.

    Showit: An Overview

    Showit Logo

    Showit is a modern, drag-and-drop website builder known for its stunning design capabilities. It’s perfect for those who want to create visually appealing sites without needing to know code.

    WordPress: An Overview

    wordpress logo

    WordPress is a powerful content management system (CMS) that powers over 40% of the web. It’s a go-to platform for bloggers, e-commerce sites, and large businesses.

    Showit vs WordPress: A Comprehensive Comparison

    Feature/AspectShowitWordPress
    Ease of UseUser-friendly, drag-and-drop interface, no coding required.Steeper learning curve, more control, coding knowledge beneficial.
    Design FlexibilityKnown for beautiful, artistic designs, great for creative sites.Endless customization with themes and plugins, versatile.
    SEO CapabilitiesBasic SEO tools, may require additional efforts for advanced SEO.Robust SEO capabilities with plugins like Yoast, preferred by experts.
    Performance and SpeedGenerally good but may vary with design complexity.Known for speed, especially with proper optimization and caching.
    PricingSubscription-based pricing with different tiers.Free to use, costs may arise from hosting, themes, plugins.
    Security MeasuresBuilt-in security features, SSL certificates.Requires regular updates, security plugins for optimal protection.
    Community and SupportOfficial support, community of designers.Extensive community support through forums, blogs, tutorials.
    Integration and PluginsLimited integration options.Thousands of plugins available for various functionalities.
    Mobile ResponsivenessDesigns are mobile-friendly, adapt to different screen sizes.Themes must be chosen carefully for mobile optimization.
    E-commerce CapabilitiesLimited e-commerce options, suitable for small stores.Robust e-commerce capabilities with plugins like WooCommerce.
    Content ManagementSimple content management, best for visual sites.Advanced content management, ideal for blogs and large sites.
    Migration and PortabilityPossible but may require professional help.Easier migration options with various tools and plugins.
    User Reviews and TestimonialsPraised for design and ease of use, criticized for limited functionality.Loved for flexibility and community support, may be complex for beginners.
    ProsBeautiful designs, ease of use.Flexibility, community support.
    ConsLimited functionality, higher cost.Steeper learning curve, potential security risks.

    Conclusion

    Choosing between Showit and WordPress is a significant decision that depends on your specific needs, budget, and skills. Both platforms offer unique features and benefits, and understanding them will help you make the best choice for your website.

    Frequently Asked Questions​

    Showit is a visual website builder known for its artistic designs and ease of use, especially for beginners. WordPress is a robust content management system (CMS) offering extensive customization and functionality. While Showit focuses on visual appeal, WordPress provides more control and versatility.

    Showit is generally considered more beginner-friendly due to its drag-and-drop interface and no coding requirement. WordPress, while offering more control and flexibility, may have a steeper learning curve for those new to website development.

    Showit operates on a subscription-based pricing model with different tiers, while WordPress itself is free to use. However, costs may arise in WordPress from hosting, themes, plugins, and other additional features.

    Migration between Showit and WordPress is possible but may require professional assistance or specific tools, depending on the complexity of the site.

    Showit offers basic SEO tools but may require additional efforts for advanced optimization. WordPress, on the other hand, has robust SEO capabilities, especially with plugins like Yoast, making it a preferred choice for SEO professionals.

    For e-commerce, WordPress typically offers more robust capabilities, especially with plugins like WooCommerce. Showit has limited e-commerce options, making it more suitable for small stores or simple selling functionalities.

    Showit offers built-in security features and SSL certificates. WordPress requires regular updates and may need additional security plugins for optimal protection. Both platforms prioritize security, but the measures may vary.

    Both Showit and WordPress offer customization options. Showit focuses on visual design with a user-friendly interface, while WordPress offers endless customization through themes, plugins, and coding.

    Showit offers official support and has a community of designers for assistance. WordPress has extensive community support through forums, blogs, tutorials, and a vast network of developers and users.

    Choosing between Showit and WordPress depends on your specific needs, preferences, budget, and skills. Showit is ideal for visually stunning, artistic sites, while WordPress provides more functionality and control. Consider factors like design, functionality, SEO, pricing, and support to make the best choice for your website.

  • Steps to fix hacked WordPress website

    Steps to fix hacked WordPress website

    Is your WordPress site hacked? Don’t panic! I’ll guide you through the steps to fix a hacked WordPress website in this article.

    First, understand that WordPress is secure. However, hacking is still possible. Various reasons could explain why your site was hacked.

    We’ve assisted many website owners over the past years. We’ve helped them recover hacked sites and remove malicious code.

    WordPress powers 43.1% of all websites on the internet. That makes it a tempting target for hackers.

    Forbes published a report with a startling fact. Almost 30,000 websites get hacked daily. Seeing your website hacked is stressful.

    A hacked site damages your reputation. It affects your customers and Google rankings. Therefore, fixing it quickly is crucial to avoid impacting your business.

    Things to know before we start

    No website is 100% secure. Hundreds of vulnerabilities are found daily. Hackers can exploit these to hack sites. It’s not always the WordPress core files at fault.

    The PHP version on your server may be the issue. It could be anything. So, use the latest versions of both the CMS and PHP.

    Google and some browsers may warn visitors about hacked sites. This warning harms your website’s reputation. Hacked websites often contain or point to inappropriate content.

    Website security must be a top priority if you run an online business. It’s vital to pick a reputable hosting company.

    Good hosting companies update their servers and scan hosted sites regularly. We’ve used LiquidWeb for years without compromise. Regular backups are also essential; ask your host for auto-backup.

    You can use online scanners like Sucuri to check for hacks. We’ve used this site to scan client websites for malicious code.

    About 40% of websites get hacked through server vulnerabilities. Good hosting, regular backups, and scanning are essential for security.

    But if you’re reading this, your site might be hacked. Or you want to secure your WordPress website.

    How to identify if a WordPress website is Hacked?

    Using View Source

    Open your website in a browser. Right-click and select “View Page Source.” Look for unfamiliar website links. Search for anything you didn’t add to your pages.

    You might find HTML iframe codes. Words like Viagra or Cialis could appear on the pages. You may not see these words or links upfront.

    Hackers often hide these with CSS. They set the properties to ‘hidden’ or ‘none.’ The page loads these hidden elements, but users don’t see them.

    When Google crawls your website’s pages, it may mark the site as spam or hacked. This occurs because of these hidden elements.


    Redirections

    If you see that your website gets redirected to any different pharma, porn or weird websites, then it is a confirmation that the site has been hacked.

    Keyword Autolink

    Some hackers insert scripts into the WordPress site which auto links the words in your website to some other websites.

    Crashing and Freezing

    Upon visiting, the site loads slowly, crash and freezes. The reason behind this is the script that has been added to the site by the hacker.

    Unnecessary Popups and Windows

    Popups, alerts and new windows to different porn or objectionable URLs open when the site is visited.

    Notices and Alert from Hosting Provider

    Most of the hosting providers send you emails and alerts if any files get infected by malicious code or scripts. If you are using shared hosting, then other sites in the host generally get affected in such situations.

    So, these are some of the techniques to find out if a website is hacked. Now let me tell you how you can fix the hacked WordPress website.

    If you want your things to get done quickly without wasting a single minute, then you can hire a professional to fix the site for you.

    Hire website security Professional

    If you’re a skilled web security professional, you can handle this. Not a coder or comfortable with servers? Then hiring a WordPress Security Expert is recommended.

    An expert can investigate the cause. They can find infected files, remove malicious code, and restore the website.

    Hackers often inject malicious code into many files. Every file on the server must be scanned and checked precisely. Even one hacked file can ruin the site again.

    As said, we have been fixing and cleaning up Malware from WordPress websites for years; so you may consider us to help you with securing your WordPress website. We charge between $99-$199 depending upon the severity.

    Well, this is a secondary option. Let me first guide you the steps to remove Malware and clean up your hacked WordPress website.

    Okay, let’s begin.

    Step 1: Scan the computer which connects to the server

    Before you start any fixes to the website, the first and foremost thing is to scan your computer, which gets connected to the server via FTP. If your computer is affected by Malware, virus and Trojans, the FTP details get stolen by the hackers. I would recommend you to use a reputed anti-virus and then connect to the server.

    Step 2: Change all the passwords

    After scanning your website, you should change the usernames and passwords of FTP, WordPress Admin area login details and hosting details. Use a strong password for all the three. You can also use a strong password generator and keep the password safe.

    Step 3: Contact the Hosting Provider

    If you are using a shared server, then ask your host to check if other sites in the host are affected. Most of the hosting providers are helpful and scan the entire server to remove the Malware and update the security settings of your files.

    We had a horrible experience with our last hosting provider which hosted our site on a shared server and didn’t bother to update the server or remove Malware, so we moved our site to a VPS after cleaning the site. You may change your host or your hosting plan. Now follow the next step if your host isn’t helpful.

    Step 4: Restore from Backup

    If you regularly backup your WordPress website, then you won’t have any issues in deleting all the hacked files and replacing those with the backup files. Don’t delete the database as you might lose the changes you have done to the posts or pages. If you don’t have a backup, then follow the next step.

    Step 5: Download WordPress from Official Website

    If you don’t have a backup, then the last thing to do is downloading the version of WordPress that your website is using from the official website and UNZIP it to a folder.

    Step 6: Remove Infected files

    Now that you have cleaned your computer and extracted the WordPress files from the official site, you can now login to your website using FTP or web-based file manager and go to the folder where you have installed your WordPress and delete all the files except wp-config.php and the wp-content folder.

    Check the wp-config.php file and other files inside the wp-content folder properly and make sure that the file doesn’t contain any malicious code. Remove additional files with weird names. You can search for a PHP function base64(); which is used by the hackers to encrypt the data. Try to remove those codes. You can also use an online base64 decoder to check and verify the encrypted infected codes.

    For example, you see some data like this PGEgaHJlZj0iaHR0cHM6Ly93d3cuaW5meXdheXMuY29tIj5JbmZ5d2F5czwvYT4 . Copy the encoded contents and decode it. The decoding code shows you the following:

    <a href="https://data.infyways.com/new">Infyways</a>

    Check all the folders inside the wp-content thoroughly. You can also remove the WordPress plugins folder and the themes which you aren’t using. If you have a clean backup of your active theme, then you can delete all the themes. Plugins can be installed later once you complete the process.

    Step 7: Re-Upload Core WordPress Files

    If you have checked all the files which are there in the server, the next step is uploading the extracted WordPress files (Step 5) into the server through FTP.

    Step 8: Update the site and files

    Once you re-upload the core files, you can now login to the backend and install all the missing plugins and themes. Activate the theme and plugins. Your site is ready now, but it is still not secured. Follow the next step and make the site secured.

    Step 9: Securing a WordPress Website

    • Download all the plugins from the official repository of WordPress.
    • Don’t’ use nulled theme or plugins. All nulled files have malicious or infected codes inside them.
    • Set the folder permission to 755 and files to 644. Avoid chmod permission 777
    • Check the list of users and see if it contains any new user with admin access. An admin has access to change the theme files directly in the wp-admin or WordPress Dashboard.
    • You can set up a firewall monitoring system by installing plugins such as Acunetix or Sucuri. These security plugins enhance security and block the attack on the website.
    • Disable file edits in the backend.
    • Limit the login attempts in the backed. This can be done by installing a plugin called Limit Login Attempts

    Step 10: Remove Google Malware Warning

    Site Harmful Browser Screenshot

    Removing Malware warning is the last step which has to be done once your site is free from malware infection. You can submit the website to Google for review once again in order to remove the warning “This site may harm your computer”. The warning can be removed using the Google Webmaster Tools.

    Conclusion

    Never use nulled WordPress themes or plugins and keep your WordPress, themes and plugins updated. If you don’t, the website may get hacked and ultimately lose rank on SERPs. The recent Google algorithm impacts the hacked or spam website. So, keeping your website secured should be your utmost priority.

    I hope the guide must have helped you to fix hacked WordPress website. If you are still facing issues, then feel free to contact us. We are happy to help you any time.

    Frequently Asked Questions​

    When your WordPress site is hacked, you can follow these steps: Scan your computer for malware, change all your passwords (FTP, WordPress admin, and hosting), contact your hosting provider, restore your website from a backup if available, remove infected files, re-upload core WordPress files, update your site and files, and secure your WordPress website. Lastly, remove the Google malware warning.

    Yes, a hacked website can be restored. If you have a clean backup of your website, you can delete all the hacked files and replace them with the backup files. If you don’t have a backup, you can manually clean the infected files, re-upload the core WordPress files, and update your site.

    WordPress websites can be hacked due to various reasons such as weak passwords, out-of-date software, plugin and theme backdoors, vulnerable file permissions, and insecure hosting providers. Hackers often target WordPress due to its popularity.

    To remove a virus from WordPress, you need to scan your website for malware, remove the infected files, and re-upload the clean files. You can use various security plugins available for WordPress to scan and remove the malware.

    You can secure your WordPress website by using strong passwords, keeping your WordPress, themes, and plugins updated, using trusted themes and plugins, limiting login attempts, implementing SSL encryption, and installing a web application firewall.

    Signs that your WordPress website has been hacked include unexpected redirects, spammy on-site content, warnings from Google or web host, unexplained accessibility issues, and website behaving strangely.

    If you can’t fix your hacked WordPress site on your own, you should contact a professional WordPress security service. They have the expertise to clean your website and secure it from future attacks.

    To prevent your WordPress website from being hacked in the future, ensure your passwords are secure, keep everything updated, use trusted themes and plugins, delete unused plugins and themes, protect your website from malware, and find a reputable hosting company.

    A nulled theme or plugin is a premium theme or plugin that has been cracked and made available for free illegally. You should avoid it because it often contains malicious or infected codes that can harm your website.

    Once your site is free from malware infection, you can submit your website to Google for review to remove the warning “This site may harm your computer”. You can do this using Google Webmaster Tools.

  • A Complete Guide to Improving WordPress Tag Clouds

    A Complete Guide to Improving WordPress Tag Clouds

    When you visit a website, you often see a bunch of words or tags grouped together, right?
    These are called tag clouds. They help you find the most popular topics on the website and make it easy for you to explore different content. But sometimes, the tag clouds in WordPress, a popular website-making tool, aren’t very good.
    Don’t worry, though! This guide will teach you how to make better tag clouds that will make your website visitors happy.

    What Are Tag Clouds?

    Tag clouds are like signposts on a website. They help you navigate through all the content available. The more a tag is used, the bigger or brighter it appears in the tag cloud. This way, visitors can easily find and explore topics they’re interested in.

    Think of your website as a huge library, and the tag cloud as the index. Just by looking at the tag cloud, users can find popular topics and dive into the content they like. Tag clouds give your audience the freedom to explore without feeling lost.

    What Makes Up a Tag Cloud?

    A tag cloud is made up of tags, which are clickable links. They are displayed in different sizes or colors based on how important they are. The size or color shows how often the tags are used, helping users explore content easily.

    Why Good Tag Cloud Design Matters

    Organizing Tags

    To make a better tag cloud, you need to sort your tags properly. Group them based on topics or how related they are. This will make your tag cloud easier to use.

    Making Tag Clouds User-Friendly

    The best websites focus on user experience. When you design your tag cloud, make sure it’s easy to use on all devices and screen sizes. This way, everyone can have a great experience, no matter what device they use.

    Making Tag Clouds Look Good

    A good-looking tag cloud can make users want to explore more. Try using cool fonts, bright colors, and nice layouts. This will make users want to click on the tag cloud and explore your content.

    How to Build Better WordPress Tag Clouds

    Picking the Right Plugin

    WordPress has many tag cloud plugins. Choose one that helps you reach your goals and lets you customize your tag cloud. Plugins like “Tag Cloud Magic” or Cool Tag Cloud let you control how your tag cloud looks and works.

    Adjusting Tag Cloud Settings

    Changing the tag cloud settings can help it match your website’s look and goals. You can change things like font size, color scheme, and how many tags are shown to make your tag cloud look good and easy to use.

    Making Tag Clouds Work on All Devices

    More people are using their phones to browse the web. So, it’s important to make sure your tag cloud looks good on all devices. Use responsive design techniques to make tag clouds that work well on different screen sizes.

    Adding Fun Visuals

    Tag clouds don’t have to be boring. Add fun visuals like icons, pictures, or custom images as tags. This will make your tag cloud more interesting and inviting.

    Best Practices for Tag Clouds

    Creating a Good Tag Structure

    A well-organized tag cloud needs a good tag structure. Look at your content and find common themes or categories. Create a logical structure that helps users navigate.

    Grouping Tags

    Tags work even better when they’re grouped into categories. For example, if you have a food blog, you could create categories like “desserts,” “main courses,” or “vegetarian.” This helps users find specific content easily.

    Being Consistent and Avoiding Duplicate Tags

    Make sure you use tags consistently across your content. Don’t use synonyms or similar terms as separate tags. This makes it easier for users to find what they’re looking for.

    Updating Tags

    Over time, you might end up with tags that you don’t use anymore. Regularly check your tag cloud and remove or combine tags that are too similar. This keeps your tag cloud up-to-date and accurate.

    Advanced Tips for Improving Tag Clouds

    Using SEO

    SEO, or Search Engine Optimization, helps your website show up in search results. Use relevant keywords in your tags and their descriptions to improve your website’s visibility. A well-optimized tag cloud can help your SEO efforts.

    Using Plugins for Customization and Optimization

    Plugins can be really helpful for customizing and optimizing your tag cloud. Try plugins like “Tag Manager” or “Custom Taxonomies Menu Widget” to unlock more customization options and improve user experience.

    Using Widgets

    Widgets let you show your tag cloud in different places on your website. Try putting the tag cloud in easy-to-find areas, like the sidebar or footer. This encourages users to engage and explore.

    Linking Tag Clouds to Related Content

    Link your tag cloud to related content on your website. When users click on a tag, take them to a page that shows related articles or posts. This encourages users to explore more and stay on your site longer.

    Making Tag Clouds More Interactive

    Adding Filtering and Sorting Options

    Let users filter or sort tags based on what they want. Add options like alphabetical sorting, popularity sorting, or category filtering. This lets users customize their exploration experience.

    Adding a Search Feature

    Make it easier for users by adding a search feature to your tag cloud. This lets users search for specific tags and find relevant content quickly.

    Using Tooltips

    Tooltips give users more information about tags. When users hover over a tag, show a tooltip with a brief description or related stats. This makes the user experience better and encourages users to engage more.

    Adding Animations

    Animations can make a lasting impression. Consider adding subtle animations or hover effects to your tag cloud. These small interactions make your tag cloud more fun and interesting.

    How to Measure Tag Cloud Performance

    Analyzing User Interactions

    Use tools like Google Analytics to track how users interact with your tag cloud. Look at things like how often users click on tags, how long they spend exploring tags, and which tags get the most clicks. This can help you understand user engagement and make improvements.

    Tracking Click-through Rates

    Find out which tags are popular by tracking how often they’re clicked. Use this data to make popular tags more noticeable. This attracts user attention and encourages them to explore more.

    Using Analytics Tools

    Use analytics tools designed for tag clouds, like “Tag Cloud Analyzer” or “Tag Manager Analytics.” These tools give you detailed insights into how your tag cloud is performing and how users are interacting with it.

    Conclusion

    Improving WordPress tag clouds is a journey. By understanding what tag clouds are, using best practices, and trying out advanced techniques, you can make your tag cloud a powerful tool that makes your website visitors happy.

  • Add Custom Attributes Dropdown to WooCommerce Product Page

    Add Custom Attributes Dropdown to WooCommerce Product Page

    WooCommerce product attributes let you define extra product data, such as size or colour to help customers know more about the product. The default Woocommerce template does have the features to display it in the additional information section but if you are looking to show it just above the cart button then you can use the WooCommerce hook woocommerce_before_add_to_cart_button. This is the best way to show custom product attributes on the shop page programmatically.

    Display Custom Products Attributes Dropdown

    The following code will work only for simple product or if you are using WooCommerce lottery. To show a list, select or a dropdown for all the custom attributes in the frontend just above the cart button you can add the code to functions.php file of the current theme you are using.

    add_action('woocommerce_before_add_to_cart_button', 'custom_product_attributes');
    
    function custom_product_attributes() {
    global $product;
    $attributes = $product->get_attributes();
    if ( ! $attributes ) {
    return;
    }
    if ($product->is_type( 'variable' )) {
    return;
    }
    echo '<div class="wc-prod-attributes"><h2>Custom Attributes</h2>';
    foreach ( $attributes as $attribute ) {
    $attribute_data = $attribute->get_data();
    $attribute_terms = $attribute_data['options'];
    $label = $attribute_data['name'];
    ?>
    <div class="wc-prod-single-attribute">
    <h3><?php echo $label; ?></h3>
    <select class="wc-custom-select-attribute" name="attribute[<?php echo $attribute_data['id']; ?>]" id="attribute[<?php echo $attribute_data['id']; ?>]">
                    <option value selected>Choose an option</option>
                    <?php foreach ( $attribute_terms as $pa ): ?>
                        <option value="<?php echo $pa; ?>"><?php echo $pa; ?></option>
                    <?php endforeach; ?>
                </select>
    </div>
    <?php
    }
    echo '</div>';
    }
    ?>

    Note: Don’t place the code in the woocommerce plugin folder. It is always advised to place the above code in functions.php of the theme you are using so that the files don’t overwrite when you update WooCommerce plugin.

    Adding Custom Attribute to the Backend

    We are using lottery plugin and wanted to show a custom attribute in the frontend. To add a custom attribute, click on the Attributes Tab. Select Custom product attribute and enter the name and the values. The dropdown values have to be separated by | as per the screenshot.

    Add Custom Attributes Dropdown to WooCommerce

    Custom Attribute Select Display

    As you can see the list shows all the options that we have added in the backend of the particular product. You can add any number of values in the backend which is shown as an option in the frontend.

    Select list woocommerce custom attribute

    Conclusion

    Using Custom Attributes at the right place in the product page will definitely help the customers in taking the right decision while purchasing the products. If you have any questions or face issues with the implementation of custom product attributes into your woocommerce page, then feel free to contact us. We will get back to you as soon as possible

  • How to fix WordPress and IE compatibility issues?

    How to fix WordPress and IE compatibility issues?

    WordPress, being a versatile platform, is used by millions worldwide. However, like any other web platform, it can sometimes face compatibility issues with certain browsers, especially older versions of Internet Explorer (IE). This guide will provide advanced solutions to instantly resolve these issues and ensure your WordPress site runs smoothly across all browsers.

    Understanding the Issue

    Before diving into the solutions, it’s essential to understand the nature of compatibility issues. WordPress themes, plugins, and custom codes might not always align with the way older browsers, like IE, interpret and display web content. This misalignment can lead to distorted layouts, malfunctioning features, or even security vulnerabilities.

    Solutions to WordPress and IE Compatibility Issues

    1. Browser Detection Using JavaScript: Implement browser-specific code by detecting the user’s browser through JavaScript. Place this code in the header file of your WordPress page or post. This method can identify common browsers like Opera, Internet Explorer, Safari, Chrome, and Firefox.
    2. Separate Style Sheets for Different Browsers: Create distinct CSS files tailored for specific browsers. For instance, if you notice that a particular CSS attribute doesn’t render well in IE but works perfectly in Firefox, you can create two separate style sheets. Use JavaScript to determine which style sheet to apply based on the user’s browser.
    3. Use the Compatibility View in IE: For users still on Internet Explorer, especially older versions like IE 11, there’s a feature called “Compatibility View.” This feature allows websites to be displayed as if the user was viewing them in an older version of IE. It can be a quick fix for many display issues.
    4. Update WordPress Themes and Plugins: Ensure that your WordPress themes and plugins are updated. Developers often release updates to address compatibility issues.
    5. Use Cross-Browser Testing Tools: Tools like the Microsoft Edge browser can help you run cross-browser compatibility checks on your site. This can be particularly useful to identify and resolve any inconsistencies.
    6. Clear Browser Cache: Sometimes, the issue isn’t with the website but with the stored cache in the browser. Clearing the cache can often resolve display issues.

    FAQs

    • How do I make my WordPress site compatible with all browsers?
      Regularly update your themes and plugins, use cross-browser testing tools, and consider implementing browser-specific code using JavaScript.
    • What is the browser compatibility plugin for WordPress?
      There are several plugins available that can help identify and fix compatibility issues. It’s essential to choose one that’s regularly updated and has good reviews.
    • Why is my WordPress site not displaying correctly?
      This could be due to outdated themes/plugins, browser cache, or compatibility issues with certain browsers.
    • How do I enable IE compatibility mode in Chrome?
      Chrome doesn’t have a native IE compatibility mode. However, there are third-party extensions available that can emulate this feature.

    Conclusion

    Ensuring your WordPress site is compatible with all browsers, especially older versions like IE, is crucial for user experience. By following the steps mentioned above, you can ensure a seamless experience for your users across all browsers.

  • WordPress Website Builder Showdown: Avada vs Elementor – Unleashing the Ultimate Battle

    WordPress Website Builder Showdown: Avada vs Elementor – Unleashing the Ultimate Battle

    When it comes to choosing a WordPress website builder, there are a lot of options to choose from like Beaver, WP Bakery, Visual Composer and lot more. However, two of the most popular choices are Avada and Elementor. Both have a lot to offer, but which one is the best? In this blog post, we’ll take a look at both software, explore their pros and cons, highlight the similarities and differences between both, and see which one is the best for developing your website.

    Choosing Between Avada & Elementor for Your Next WordPress Project – What’s In It For You?

    Choosing between these two popular WordPress page builders can be a difficult decision. Avada and Elementor are both powerful page builders that offer drag-and-drop functionality, easy customization, and incredible design options. They both can deliver a high-quality website design and offer many configuration options, an intuitive interface, and plenty of customization choices to choose from. However, each of them has the strengths and weaknesses that set both apart from each other.

    When deciding which one to use for your next project, it is important to consider what is important to you as a designer or webmaster. If you are looking for a lot of design options or want to be able to build any type of website with the same tool, then Avada may be the best option for you. If you need more flexibility in terms of design, then Elementor will be a better choice for website building.

    Pros & Cons of Using Avada & Elementor

    Avada and Elementor are two of the most popular website builder software in the market today. They have a lot of similarities and differences.

    • The main difference between Avada and Elementor is that Avada has more templates to choose from, but Elementor is easier to use for beginners.
    • Both have drag-and-drop features, but Elementor is more intuitive for this purpose. Elementor comes with an intuitive interface, which cuts down on the time spent on creating the site.
    • Avada has a better SEO function than Elementor, but at the same time, it’s less user-friendly than Elementor when it comes to adding content to your website.
    • Elementor offers better customer support than Avada, but at the same time, it’s less flexible than Avada with some of its features like contact forms or popups.

    Avada vs. Elementor Review – Which is Better?

    Avada is a premium WordPress theme that offers more than 5000 different features, including an advanced drag-and-drop page builder. It is highly customizable, providing you with all the tools you need to create any type of website in minutes. If you’re looking for powerful website builder software, Avada is a great option. It’s easy to use and offers a wide range of features, making it a great choice for both novice and experienced web developers.

    With Elementor, you can create exquisite, responsive websites with ease. Plus, there’s no need to code! Just drag and drop your way to a stunning website. From a wide selection of templates to a wide range of widgets, Elementor has everything you need to create a profitable website. It is an ideal tool for both the beginner and the pros. And, it’s free! If you’re looking for a powerful, yet easy-to-use website builder software, then you must check out Elementor.