### Color Utilities
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Functions for color manipulation, including getting contrasting foreground colors, adjusting brightness, and converting HEX to RGBA.
```APIDOC
## Color Utilities
### Description
Astra provides color manipulation functions for generating foreground colors, adjusting brightness, and converting between HEX and RGBA formats.
### Functions
#### `astra_get_foreground_color( $hex_color )
##### Parameters
- **hex_color** (string) - Required - The background color in HEX format.
##### Returns
- (string) - Contrasting foreground color ('#ffffff' or '#000000').
##### Example
```php
// Get contrasting foreground color (black or white)
$bg_color = '#336699';
$text_color = astra_get_foreground_color($bg_color); // Returns "#ffffff"
$light_bg = '#f5f5f5';
$dark_text = astra_get_foreground_color($light_bg); // Returns "#000000"
```
#### `astra_adjust_brightness( $hex_color, $percentage, $type = 'lighten' )
##### Parameters
- **hex_color** (string) - Required - The base color in HEX format.
- **percentage** (int) - Required - The percentage to adjust brightness.
- **type** (string) - Optional - 'lighten', 'darken', or 'reverse' (auto light/dark). Defaults to 'lighten'.
##### Returns
- (string) - The adjusted HEX color.
##### Example
```php
// Adjust color brightness
$base_color = '#336699';
$lighter = astra_adjust_brightness($base_color, 50, 'lighten');
$darker = astra_adjust_brightness($base_color, 50, 'darken');
$auto = astra_adjust_brightness($base_color, 30, 'reverse'); // Auto light/dark
```
#### `astra_hex_to_rgba( $hex, $opacity = 1 )
##### Parameters
- **hex** (string) - Required - The HEX color code.
- **opacity** (float) - Optional - The opacity value (0 to 1). Defaults to 1.
##### Returns
- (string) - The RGBA or RGB color string.
##### Example
```php
// Convert HEX to RGBA
$hex = '#336699';
$rgba = astra_hex_to_rgba($hex, 0.5); // "rgba(51,102,153,0.5)"
$rgb = astra_hex_to_rgba($hex); // "rgb(51,102,153)"
```
### Integration Example
```php
// Use in dynamic CSS generation
add_filter('astra_dynamic_theme_css', function($css) {
$theme_color = astra_get_option('theme-color');
$hover_color = astra_adjust_brightness($theme_color, 20, 'darken');
$button_css = array(
'.ast-button:hover' => array(
'background-color' => $hover_color,
),
);
return $css . astra_parse_css($button_css);
});
```
```
--------------------------------
### Retrieve Astra Responsive Breakpoints
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Get default and modified responsive breakpoints for tablet and mobile devices using 'astra_get_tablet_breakpoint()' and 'astra_get_mobile_breakpoint()'. You can also retrieve breakpoints with an offset.
```php
'#ffffff',
'background-image' => 'https://example.com/image.jpg',
'background-repeat' => 'no-repeat',
'background-position' => 'center center',
'background-size' => 'cover',
'background-attachment' => 'fixed',
'background-type' => 'image',
'overlay-type' => 'classic',
'overlay-color' => 'rgba(0,0,0,0.5)',
'overlay-opacity' => '0.5',
);
$bg_css = astra_get_background_obj($bg_config);
// Returns array ready for astra_parse_css():
// array(
// 'background-image' => 'linear-gradient(to right, rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url(https://example.com/image.jpg)',
// 'background-repeat' => 'no-repeat',
// 'background-position' => 'center center',
// 'background-size' => 'cover',
// 'background-attachment' => 'fixed',
// )
// Use in dynamic CSS
add_filter('astra_dynamic_theme_css', function($css) {
$header_bg = astra_get_option('header-bg-obj', array());
$bg_css_props = astra_get_background_obj($header_bg);
$header_styles = array(
'.site-header' => $bg_css_props,
);
return $css . astra_parse_css($header_styles);
});
// Responsive background handling
$responsive_bg = astra_get_option('site-layout-outside-bg-obj-responsive');
$desktop_bg = astra_get_responsive_background_obj($responsive_bg, 'desktop');
$tablet_bg = astra_get_responsive_background_obj($responsive_bg, 'tablet');
$mobile_bg = astra_get_responsive_background_obj($responsive_bg, 'mobile');
```
--------------------------------
### Customize Astra Content Area with Hooks
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Leverage 'astra_content_before', 'astra_entry_before', 'astra_entry_content_before', and 'astra_entry_content_after' hooks to modify the content area. This includes adding breadcrumbs, share buttons, or author bios conditionally.
```php
' . get_share_buttons() . '';
}
});
add_action('astra_entry_content_after', function() {
if (is_single()) {
echo '
' . get_author_bio() . '
';
}
});
```
--------------------------------
### Integrate WooCommerce Features
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Customize WooCommerce shop layouts, columns, and product displays using Astra-specific hooks. Ensure compatibility checks are performed before executing logic.
```php
cart->get_cart_contents_count();
return '
' . $count . '
';
}
return $content;
}, 10, 3);
// Filter shop page layout
add_filter('astra_get_content_layout', function($layout) {
if (function_exists('is_shop') && (is_shop() || is_product_category())) {
return 'plain-container';
}
if (function_exists('is_product') && is_product()) {
return 'plain-container';
}
return $layout;
});
// Custom single product structure
add_action('woocommerce_single_product_summary', function() {
// Custom content after product summary
echo '';
// Add custom badges
echo '
';
}, 35);
```
--------------------------------
### Retrieve Theme Options with astra_get_option
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Use this function to fetch theme settings from the database, supporting default fallbacks and dynamic filtering.
```php
16,
'tablet' => '',
'mobile' => '',
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
));
// Get color settings using CSS variables
$text_color = astra_get_option('text-color', 'var(--ast-global-color-3)');
$link_color = astra_get_option('link-color', 'var(--ast-global-color-0)');
$theme_color = astra_get_option('theme-color', 'var(--ast-global-color-0)');
// Get container layout settings
$content_width = astra_get_option('site-content-width', 1200);
$sidebar_width = astra_get_option('site-sidebar-width', 30);
// Filter option values dynamically
add_filter('astra_get_option_site-layout', function($value, $option, $default) {
if (is_page_template('full-width.php')) {
return 'ast-full-width-layout';
}
return $value;
}, 10, 3);
```
--------------------------------
### Manipulate Colors and Themes
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Functions for calculating foreground colors, adjusting brightness, and converting color formats for use in dynamic CSS.
```php
array(
'background-color' => $hover_color,
),
);
return $css . astra_parse_css($button_css);
});
```
--------------------------------
### Manage Theme Options with astra_update_option and astra_delete_option
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Programmatically update or delete theme settings, utilizing action hooks to trigger logic before or after changes.
```php
array('top' => 20, 'right' => 30, 'bottom' => 20, 'left' => 30),
'tablet' => array('top' => 15, 'right' => 20, 'bottom' => 15, 'left' => 20),
'mobile' => array('top' => 10, 'right' => 15, 'bottom' => 10, 'left' => 15),
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
),
'top',
'desktop'
);
// Returns: "20px"
```
--------------------------------
### Generate Responsive CSS with Astra Breakpoints
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Use 'astra_parse_css' in conjunction with 'astra_get_tablet_breakpoint()' and 'astra_get_mobile_breakpoint()' within the 'astra_dynamic_theme_css' filter to generate responsive CSS rules for different screen sizes.
```php
array('font-size' => '18px'),
);
$css .= astra_parse_css($desktop);
// Tablet styles (max-width: tablet breakpoint)
$tablet = array(
'.my-element' => array('font-size' => '16px'),
);
$css .= astra_parse_css($tablet, '', astra_get_tablet_breakpoint());
// Mobile styles (max-width: mobile breakpoint)
$mobile = array(
'.my-element' => array('font-size' => '14px'),
);
$css .= astra_parse_css($mobile, '', astra_get_mobile_breakpoint());
return $css;
});
```
--------------------------------
### Post Meta Options API
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Functions for retrieving per-post/page settings that override global theme options.
```APIDOC
## Post Meta Options
### Description
Retrieves per-post/page settings that override global theme options, enabling granular control over individual content items.
### Method
`astra_get_option_meta( string $option_slug, mixed $default = null, bool $only_meta = false, string $meta_key = '', int|WP_Post $post_id = null ): mixed
### Parameters
#### Function Parameters
- **option_slug** (string) - The unique identifier for the meta option.
- **default** (mixed) - The default value to return if the meta option is not found. Defaults to null.
- **only_meta** (bool) - If true, only retrieves meta values and does not fall back to global options. Defaults to false.
- **meta_key** (string) - The meta key to use when `only_meta` is true. Defaults to ''.
- **post_id** (int|WP_Post) - The ID of the post or WP_Post object to retrieve meta from. If null, the current post is used. Defaults to null.
### Request Example
```php
// Get post-specific content layout (falls back to global option)
$content_layout = astra_get_option_meta('ast-site-content-layout', 'default');
// Get sidebar layout for current post
$sidebar = astra_get_option_meta('site-sidebar-layout', 'default');
// Only get meta value (don't fall back to global)
$only_meta = astra_get_option_meta('site-sidebar-layout', '', true);
if (false === $only_meta) {
// No post-specific setting exists
}
// Get meta from specific post ID
$post_id = 123;
$layout = astra_get_option_meta('ast-site-content-layout', 'default', false, '', $post_id);
// Use in theme templates
if (is_singular()) {
$container_layout = astra_get_option_meta('ast-site-content-layout');
if ('default' === $container_layout || empty($container_layout)) {
$container_layout = astra_get_option('ast-site-content-layout');
}
}
```
### Response
#### Success Response (200)
- **mixed** - The value of the requested post meta option or the fallback global option.
```
--------------------------------
### Customize Astra Footer with Hooks
Source: https://context7.com/projectestac/wordpress-theme-astra/llms.txt
Utilize 'astra_footer_before', 'astra_footer_content', and 'astra_body_bottom' actions to add elements before the footer, within the main footer area, or just before the closing body tag, suitable for scripts.
```php
Subscribe to our newsletter';
});
add_action('astra_footer_content', function() {
// Main footer content area
});
add_action('astra_body_bottom', function() {
// Before closing