You can use wp_head
action to add something to head section. You can change the output according your needs.
<?php
add_action('wp_head','add_meta_des');
function add_meta_des() {
if(is_single())
{
global $wp_query;
$post = $wp_query->post;
$page_id = $post->ID;
$page_object = get_page( $page_id );
$content = wp_trim_words($page_object->post_content,30);
$output="<meta name="description" content="".get_the_title()."--".$content.""/>";
echo $output;
}
}
?>
Related Posts:
- Generating rel=prev and rel=next only on wordpress categories
- Add tags to the section via functions.php
- In a WordPress plugin, how do you output HTML code inside the DOM header? [closed]
- Clean up output added via wp_head()
- How do you completely remove the default header and footer using functions.php?
- Passing a variable via wp_head and then calling it on the page
- get_next_posts_link not working without parameter max_num_pages
- adding custom script to functions file
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- How can I modify the element on all pages?
- New custom menu created. how to apply it?
- How to add link rel tags on paginated posts?
- save_post hook – headers already sent?
- Init hook for header send
- Echo a div to header.php from functions.php
- Adding a second email address to a completed order in WooCommerce [closed]
- Possible to search by author name with default WordPress search function?
- Advantages and disadvantages of using automatic-feed-links
- Influence of WordPress functions on site speed
- Is it possible to override this function/class in a child theme?
- When new user register then add new user role
- Change meta tags programatically
- Convert hyphen to underscore in permalinks
- Remove bulk actions based on user role or capabilities
- Set first oembed in post to a global variable or function
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- Use a function to update post meta based on other post meta
- How to override filter in child theme?
- Use Exact Image Size using add_image_size
- How can I tell when a user is logged in?
- Enqueue Style in Functions.php
- How allow users to save list of posts?
- Formatting Multiple add_theme_support Arguments
- Limit posts only on home page – ideally in functions.php
- Make Categories a Dropdown Menu in Media Library
- How to add css class to image attached in all the posts?
- If is multiple page templates
- What will happen if I delete the functions.php file?
- how to add an image to the footer?
- How to properly add function called by action-hooked function to functions.php?
- Get Current User info using wp_localize_script, in functions.php
- How to add new embed handler not supported by oembed?
- How do I permanently Disable Attachment Post URL
- Need to add class=”lightbox” for every single post image
- Child Theme files – what is needed?
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Stuck on maintenance mode
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- How to remove style attribute in WordPress RSS output?
- Multiple Loops Meta Data
- Update user meta of author when post content is viewed
- If ACF field is empty show different value [closed]
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- How i can put $_GET codes in function.php?
- Is there a way to direct unregistered user to registration page when click a link?
- Auto log in hook is requiring a page refresh
- How to get an attachment id from a filename
- how to get the post ID from wp_insert_post
- Possible to merge these two functions?
- How can I set the SRC URL of the custom logo image?
- The Capability to choose post/page template
- The_content and Preg_replace in loaded Iframe [closed]
- dynamic site link for future migration in echo do_shortcode()
- Hide tab Buddypress profile for visitors, not logged in users
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Add a mature content warning to first-time visitors
- Show Featured Image in else statement
- Any adverse effects of adding apply_filters to a function?
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- Custom user role still showing up after deletion, ideas?
- wordpress built-in Jalali date convertor
- WordPress Function Assistance with Loop
- Populate acf-field, depending on block name
- Add Change role button for list of user in an event
- Exclude admins from query get posts
- I am trying to set post terms to a custom taxonomy
- how to increase connection time
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- Show users last read posts for each user?
- Disable links to images only if link is an image
- WordPress Javascript Widget jQuery Dependency Issue
- Open image size links in a page instead of direct image link
- Allow tags and attributes in post and pages content
- Function to get thumbnail img source
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function
- Do something when user creates post (that’s pending)
- Will my WordPress site become vulnerable after adding this functions which allows more HTML tags for subscribers?
- Add product to cart from functions.php
- Text before price on WooCom
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Change Post status based on custom field date +1 day
- How to add height and width dimensions automatically to archive descriptions
- How to store page-{id}.php templates in custom folder