Skip to content

Commit

Permalink
Add custom shortcodes: aldine_page_section, aldine_call_to_action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Zimmerman committed Feb 4, 2018
1 parent 0351c3e commit 2bb6dc0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
6 changes: 6 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'customizer',
'filters',
'helpers',
'shortcodes',
'tags',
];

Expand All @@ -52,13 +53,18 @@
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 );
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' );
Expand Down
2 changes: 1 addition & 1 deletion inc/helpers/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions inc/shortcodes/namespace.php
Original file line number Diff line number Diff line change
@@ -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']
);
}

0 comments on commit 2bb6dc0

Please sign in to comment.