Browse Source

Add custom shortcodes: aldine_page_section, aldine_call_to_action.

pull/81/head
Ned Zimmerman 7 years ago
parent
commit
2bb6dc088a
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 6
      functions.php
  2. 2
      inc/helpers/namespace.php
  3. 58
      inc/shortcodes/namespace.php

6
functions.php

@ -29,6 +29,7 @@ $includes = [
'customizer',
'filters',
'helpers',
'shortcodes',
'tags',
];
@ -52,6 +53,7 @@ add_filter( 'body_class', '\Aldine\Filters\body_classes' );
add_filter( 'excerpt_more', '\Aldine\Filters\excerpt_more' );
add_filter( 'query_vars', '\Aldine\Filters\register_query_vars' );
add_filter( 'wp_nav_menu_items', '\Aldine\Filters\adjust_menu', 10, 2 );
add_filter( 'the_content', 'do_shortcode' );
add_action( 'widgets_init', '\Aldine\Actions\widgets_init' );
add_action( 'wp_enqueue_scripts', '\Aldine\Actions\enqueue_assets' );
add_action( 'updated_option', '\Aldine\Actions\add_color_variants', 10, 3 );
@ -59,6 +61,10 @@ add_action( 'customize_register', '\Aldine\Customizer\customize_register' );
add_action( 'customize_preview_init', '\Aldine\Customizer\customize_preview_js' );
add_action( 'customize_controls_enqueue_scripts', '\Aldine\Customizer\enqueue_color_contrast_validator' );
// Shortcodes
add_shortcode( 'aldine_page_section', '\Aldine\Shortcodes\page_section' );
add_shortcode( 'aldine_call_to_action', '\Aldine\Shortcodes\call_to_action' );
// Catalog page: Network admin controls
add_action( 'admin_enqueue_scripts', '\Aldine\Admin\admin_scripts' );
add_action( 'wp_ajax_pressbooks_aldine_update_catalog', '\Aldine\Admin\update_catalog' );

2
inc/helpers/namespace.php

@ -308,7 +308,7 @@ function handle_contact_form_submission() {
function has_sections( $post_id ) {
$post_content = get_post_field( 'post_content', $post_id );
if ( ! empty( $post_content ) ) {
if ( strpos( $post_content, 'page-section' ) ) {
if ( strpos( $post_content, 'page-section' ) || strpos( $post_content, 'aldine_page_section' ) ) {
return true;
} else {
return false;

58
inc/shortcodes/namespace.php

@ -0,0 +1,58 @@
<?php
/**
* Aldine Shortcodes
*
* @package Aldine
*/
namespace Aldine\Shortcodes;
/**
* Shortcode for Page Section.
*
* @param array $atts
* @param string $content
*
* @return string
*/
function page_section( $atts, $content = null ) {
$atts = shortcode_atts(
[
'title' => 'Page Section',
'variant' => '',
],
$atts,
'aldine_page_section'
);
return sprintf(
'<div class="page-section%1$s"><h2>%2$s</h2>%3$s</div>',
( $atts['variant'] ) ? " page-section--{$atts['variant']}" : '',
$atts['title'],
$content
);
}
/**
* Shortcode for custom Call to Action.
*
* @param array $atts
*
* @return string
*/
function call_to_action( $atts ) {
$atts = shortcode_atts(
[
'link' => '#',
'text' => 'Call To Action',
],
$atts,
'aldine_call_to_action'
);
return sprintf(
'<a class="call-to-action" href="%1$s" title="%2$s">%2$s</a>',
$atts['link'],
$atts['text']
);
}
Loading…
Cancel
Save