I suspect you’re doing this too early. The loop isn’t setup yet when init
is run, so you need to hook it somewhere else. wp_print_scripts
and wp_print_styles
or get_header
are always nice choices. 😉
Related Posts:
- Why isn’t is_page working when I put it in the functions.php file?
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- Can shortcodes contain conditional statements? Even without them my shortcode renders blank page
- If function exists, and array is met, echo function?
- Conditions for Users and Visitors
- Conditional function for excluding first image from content, not working
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- How to display content If function exist/condition true?
- restrict access to specific urls on a specific period of time
- Using conditionals, maybe from a DB, to register & enqueue files, for varying pages, in functions.php
- paginate_links() don’t properly work in search.php?
- How to influence the information displayed on widget inside wp-admin
- Remove Container Element From wp_nav_menu() Markup
- WordPress function like is_category for subcategory? is_subcategory?
- How can I get $id variable in widget’s form function?
- Using a private method as an action callback from within a class
- difference between add_object_page and add_menu_page
- How to activate “Description” metabox for menu item programmatically?
- Make WordPress size and name images for Retina.js
- Pinterest Integration Using functions.php
- Adding WooCommerce to a Custom Theme – not working [closed]
- WooCommerce add_action hook results in 500 error
- Advice: Template structure – php blocks in sidebar or someting else?
- Changing itemprop from logo to image on custom logo?
- wp_get_post_terms() returns WP_Error in functions.php but in template it works
- Move jQuery and Migrate to footer?
- Make menu structure match page heirarchy on page parent change
- Change Rating range in Link Manager
- function to erase swear words
- str_replace function in theme
- Function call via ajax – can’t figure it out?
- How to add nav menu items to a specific position within a menu
- woocommerce: change default setting > is_sold_individualy function
- WordPress Menuing Question :focus
- call of javascript function to external url always blocked by cors
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- wp-comment author- url +, email filter hook
- What WordPress function to use to get meta value by using meta keys?
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Create a custom taxonomy that will be used to create and filter markers in a Google Map
- Adding an external HTML link to a post thumbnail
- Overwriting the menu break points of twentysixteen in child theme
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- How to create an onclick event on an image in a post?
- using jQuery on only one page
- Help With Creating Shortcode
- Setting a default text for excerpts of a particular category
- How can I use Woocommerce $product->get_attribute in functions.php? (if at all)
- How to set default post editor based on role?
- Solved: redirect to another page using functions.php
- Getting the teaser text without overriding global variables
- How do I place a function in a standalone page?
- Problem in using Customizer
- Ajax resetting my global variable
- Problem enqueuing scripts on not single posts
- Do I Need to Prefix Variables Inside Functions?
- referencing the current user in a page i created in wordpress
- is_main_query() always returning false
- Render page with specific id from functions.php
- Display Child Pages if no child Exists Display Siblings
- How to show ACF value under post/page title in wp-admin
- Undefined variable issue for wp_get_attachment_image_url
- Counting posts and trigger it [closed]
- ACF Flexible in TCPDF
- How do i tweak my wp Post title base on category of the post
- Why isn’t comment validation working?
- I’m creating a online store for my website, my aim is to add description to products in home page only how can i achieve it?
- modifying every other element’s class inside while loop
- Adding Custom Body Class for Page: Shop
- Menu and category highlighting for a single post
- “Conditional query tags do not work before the query is run. Before > then, they always return false. “
- Change ‘Categories’ to ‘Topics’
- Is it possible to use ‘wp_insert_post’ function within a for loop?
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- Code I am placing in the wp_footer is going outside the entire HTML frame!
- How to assign results to variables?
- Restoring pages in wordpress
- Redirect after login to current URL
- Restrict certain roles registrations by domain
- Replacing term/taxonomy archive pages with search queries
- Different body image backgrounds on different pages, posts and categories
- Hide certain post types from editors
- Language switcher for subdomains
- Function to draw random image from specified category destroys site logic – why?
- Issues with add_query_arg() not passing a variable
- Add Function For Instances of Custom Text in Multiple Category IDs to display in post content
- Move captions under gallery images in twenty fourteen theme
- Force changing the Site Title and add link
- create submenu page – error function not found or invalid function name
- How to add a class name to the ancestor of a post?
- is_user_logged_in() isn’t working
- Retrive post by tags PHP code
- Sorting date results from a query
- Using is_plugin_active within functions.php
- Button generate a random URL [closed]
- Add custom css to theme
- How do I add functionality to images?
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- How to add more than one menu for logged in members?