How to know if user logged in

<?php if ( is_user_logged_in() ) { echo ‘<script type=”text/javascript”>var logged_in=true;</script>’; } else { echo ‘<script type=”text/javascript”>var logged_in=false;</script>’; } ?>

How to modify files inside wp-includes directory in wordpress

I wouldn’t recommending any core files. Instead, you can filter the title and make your changes, like so: add_filter( ‘document_title_parts’, function( $title ) ) { // $title is an array of parts if ( strlen( $title[‘title’] ) > 10 ) { $title[‘title’] = substr( $title[‘title’], 0, 5 ); // Show only first 5 characters } … Read more

Get rid of the widget Item Class=”widget-item”

The most straightforward way would be to overwrite this in your CSS file, for instance like this: .widgettitle { padding: 0; margin: 0; } Alternatively you can change the name of the class when registering your widget (possibly in your functions.php file) – look for the ‘before_title’ parameter. Here’s and example form the original twentysexteen … Read more

Get category URL for current post

Pass the category id into get_category_link(): <?php $category = get_the_category(); $link = get_category_link( $category[0]->term_id ); ?> Update Outputting in template: <?php $category = get_the_category(); $first_category = $category[0]; echo sprintf( ‘<a href=”https://wordpress.stackexchange.com/questions/274018/%s”>%s</a>’, get_category_link( $first_category ), $first_category->name ); ?>

WordPress Shortcode function display outside of widget

I think the problem lies with functions like the_title() vs get_the_title() This seem to work: if (!function_exists(‘footer_get_latest_post’)) { function footer_get_latest_post() { $footerPost=””; $args = array(‘posts_per_page’ => 1 ); $recent_posts = new WP_Query($args); while( $recent_posts->have_posts() ) { $recent_posts->the_post(); $footerPost=”<div class=”footer-post-thumb”>” . get_the_post_thumbnail(‘thumbnail’) . ‘</div>’; $footerPost .= ‘<div class=”footer-post-content”><h3>’ . get_the_title() . ‘</h3>’; $footerPost .= get_the_content() . … Read more

Security for data obtained from the database

Well, it depends on the context. Usually we don’t need to protect data for only showing it in frontend. But the best practice is, always escape or validate data, no matter where they comes from. Like for your case you can do that like below- <label><?php echo esc_html( $data[‘title’] ); ?></label> <input type=”text” value=” <?php … Read more